Using Page ID in Templates

From EPrints Documentation
Revision as of 15:12, 17 July 2024 by Drn@ecs.soton.ac.uk (talk | contribs) (Removed reference to pagehooks)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

From EPrints 3.4.3 onwards, it is possible to include the ID of a page dynamically into its template. This facilitates writing page-specific CSS to control the appearance of specific pages and the HTML elements they contain. This is acheived by setting a pin for the page ID, which is generated from the page being loaded. EPrints has two main types of pages:

Static
This includes .xpage files found under cfg/static/ or cfg/lang/en/static, such as the homepage or information page, eprint abstract/summary pages (e.g. /id/eprint/123/) and browse view pages (e.g. /view/year/2022.html).
Dynamic
This includes pages generated from a Screen Plugins, such as the search pages and back-end management/adminstration pages for editing eprints or managing the subject tree.

Depending on the type of page the page ID pin will take on a different form. AlL dynamic pages will use the class name of the Screen plugin, converting non-alphanumeric (nor underscore) characters into underscores. So EPrint::Edit becomes EPrint_Edit. Static pages will use the path of the static page, prepended by static. So the homepage which is on the root of the path will just have the page ID static whereas the information page will have the page ID static_information. Abstract pages will have the page ID static_abstract and browse view pages will have the Page ID static_view_year for the homepage of the year view static_view_year for an index of the year view and static_view_year_page for a listing for a particular year. Where a browse view may have additional menu pages like for different letters of the alphabet for the creators browse view, if you click to go to one of these menus the page ID will append _index (e.g. static_view_creators_index.

To apply the page ID pin to a template you need to use the markup {pin:page_id}. Let us say you want to add this page ID as the id to the <body> tag of the template this might look as follows:

<body id="page_{pin:page_id}">

This would further prepend the prefix page_ to the ID of the body tag, so if you loaded an abstract page (after refreshing abstracts) it would look like:

<body id="page_static_abstract">

This could then be used in some custom CSS file to maybe reduce the size of the h1 heading because your publications have very long titles and the font size is too large for abstract pages. E.g.

#page_static_abstract h1#page-title {
    font-size: 1.8em;
}

You can place the markup for the page ID pin under whichever attribute of whatever element you want. It will only work in template files and not in static, citation or workflow files.