Difference between revisions of "API:EPrints/Apache/Template"

From EPrints Documentation
Jump to: navigation, search
Line 31: Line 31:
 
A template file is written in XML and contains a mix of HTML element and dynamic pins. Pins are locators for content that, when a page is requested, are replaced with the page's title, content etc.
 
A template file is written in XML and contains a mix of HTML element and dynamic pins. Pins are locators for content that, when a page is requested, are replaced with the page's title, content etc.
  
Some {{API:PodLink|file=|package_name=|section=Default Pins|text=default pins}} will always be available and include things like the page title and content.
+
Some [[API:default pins|EPrints::Apache::Template/Default Pins]] will always be available and include things like the page title and content.
  
 
If you need to include dynamic content in the page use a pin generated via [[API:EPrints/Apache/Template#Dynamic_Pins|Dynamic Pins]].
 
If you need to include dynamic content in the page use a pin generated via [[API:EPrints/Apache/Template#Dynamic_Pins|Dynamic Pins]].

Revision as of 16:07, 16 April 2012

EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


API: Core API

Latest Source Code (3.4, 3.3) | Revision Log | Before editing this page please read Pod2Wiki


NAME

EPrints::Apache::Template - renders a page using a template


SYNOPSIS

<?xml version="1.0" standalone="no"?>
<!DOCTYPE html SYSTEM "entities.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epc="http://eprints.org/ep3/control">
  <head>
	  <title><epc:pin ref="title" textonly="yes"/> - <epc:phrase ref="archive_name"/></title>
  ...


DESCRIPTION

Templates are used to generate the basic layout of the pages in your repository. Different templates can be used to customise sub-sections, or even individual pages.

A template file is written in XML and contains a mix of HTML element and dynamic pins. Pins are locators for content that, when a page is requested, are replaced with the page's title, content etc.

Some EPrints::Apache::Template/Default Pins will always be available and include things like the page title and content.

If you need to include dynamic content in the page use a pin generated via Dynamic Pins.

Template files are read from EPrints::Repository/template_dirs. If you want to customise the template you should copy it into your repository, rather than editing the system-wide template.


Static HTML Pages

Static files with the .xpage extension are rendered using templates:

  <?xml version="1.0" encoding="utf-8"  standalone="no"  ?>
  <!DOCTYPE page SYSTEM "entities.dtd" >
  <xpage:page xmlns="http://www.w3.org/1999/xhtml" xmlns:xpage="http://eprints.org/ep3/xpage" xmlns:epc="http://eprints.org/ep3/control">
    <xpage:template>default</xpage:template>
    <xpage:head>
      <style type="text/css">h1 { text-weight: bold }</style>
    </xpage:head>
    <xpage:title>My first XPage</xpage:title>
    <xpage:body>
      Writing XPages is easy.
    </xpage:body>
  </xpage:page>

<xpage:template> is a special pin that, instead of supplying content to the template, changes the template used for rendering. The content is just the template name (without the .xml extension).


Default Pins

  • title
The title of the page.
  • page
The page content.
  • login_status_header
HTML <head> includes for the login status of the user - currently just some JavaScript variables.
  • head
Page-specific HTML <head> contents.
  • pagetop
(Unused?)
  • login_status
A menu containing EPrints::Plugin::Screens that appear in key_tools. The content from each plugin's render_action_link is rendered as a HTML <ul> list.
Historically this was the login/logout links plus key_tools but since 3.3 login/logout are Screen plugins as well.
  • languages
The render_action_link from EPrints::Plugin::Screen::SetLang.


Dynamic Pins

In cfg.d/dynamic_template.pl:

  $c->{dynamic_template}->{function} = sub {
    my( $repo, $parts ) = @_;
  
    $parts->{mypin} = $repo->xml->create_text_node( "Hello, World!" );
  };

In archives/[archiveid]/cfg/templates/default.xml (copy from lib/templates/default.xml if not already exists):

  <epc:pin ref="mypin" />

Or, for just the text content of a pin:

  <epc:pin ref="mypin" textonly="yes" />


METHODS

SEE ALSO

The directories scanned for template sources are in EPrints::Repository/template_dirs.


COPYRIGHT

Copyright 2000-2012 University of Southampton.

This file is part of EPrints http://www.eprints.org/.

EPrints is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

EPrints is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with EPrints. If not, see http://www.gnu.org/licenses/.