print page  |  view normal version 

Section 5.2 - Template syntax

Template files (*.tpl) are typically just HTML files with some specially-formed comments in them. Here's how it all works:

Built-in variables

The following built-in variables are available for use in all templates:

  • PAGE_NAME: The visible name of the current page
  • PAGE_URLNAME: The URL string of the current page
  • USERNAME: The username of the currently logged-in user
  • SITE_NAME: The name for the website
  • SITE_DESC: The description of the website
  • TOOLBAR: The contents of the bar labeled "page tools"
  • SCRIPTPATH: Path to Enano installation root, relative to the server's document root. Example of usage: <img src="{SCRIPTPATH}/images/error.png" />
  • CONTENTPATH: The prefix for a page URL string. Example of usage: <a href="{CONTENTPATH}{NS_SPECIAL}About_Enano">About Enano</a>
  • ADMIN_SID_QUES: Elevated auth key, if applicable. In the form of "?auth=key_here" or left blank if $session->auth_level <= USER_LEVEL_MEMBER.
  • ADMIN_SID_AMP: Elevated auth key, if applicable. In the form of "&auth=key_here" or left blank if $session->auth_level <= USER_LEVEL_MEMBER.
  • ADMIN_SID_AUTO: Same as the previous two, except the first character is determined by whether there is a "?" in CONTENTPATH or not.
  • ADMIN_SID_AMP_HTML: Elevated auth key, if applicable. In the form of "&amp;auth=key_here" or left blank if $session->auth_level <= USER_LEVEL_MEMBER.
  • ADMIN_SID_RAW: Set to JUST the elevated auth key if applicable. Will be a hexadecimal string or blank if $session->auth_level <= USER_LEVEL_MEMBER.
  • ADDITIONAL_HEADERS: HTML headers added by a plugin. Should be used just before the </head> tag in header.tpl and simple-header.tpl
  • COPYRIGHT: The site's official copyright notice
  • TOOLBAR_EXTRAS: The drop-down portion of the page toolbar.
  • REQUEST_URI: The hostname of the server + the request URI. Will be something like "www.yoursite.com/enano/index.php"
  • STYLE_LINK: If your stylesheets contain template code, this contains the URI to Special:CSS.
  • LOGIN_LINK: Used for the login button on the sidebar. Should probably be ignored.
  • LOGOUT_LINK: Same, except used for logouts.
  • ADMIN_LINK: Same, except used to open the admin panel.
  • THEME_LINK: Same, except used to open the theme change UI.
  • SEARCH_ACTION: Form action for the search form.
  • INPUT_TITLE: Hidden form field containing the page title. Used when contentPath is something like "/index.php?title="
  • INPUT_AUTH: Same, except contains the current elevated auth key, if applicable.
  • TEMPLATE_DIR: Path to the current theme's root directory, relative to the document root
  • THEME_ID: Theme currently in use
  • STYLE_ID: Style currently in use
  • JS_DYNAMIC_VARS: A <script> block that sets several important Javascript variables.
  • UNREAD_PMS: An integer containing the number of unread private messages the user has. Only use when the user is logged in.
  • URL_ABOUT_ENANO: URI to the About Enano page.

Built-in booleans

The following built-in true/false values are available for all templates:

  • auth_admin: Set to true if the user has administrative privileges.
  • user_logged_in: Set to true if the user is logged in.
  • opera: Set to true if the user is using the Opera browser (to accommodate for some hacks in Oxygen)
  • auth_rename: Set to true if the user has authorization to rename the current page. This allows the double-click in-line rename on page titles.
  • enable_uploads: Set to true if file uploads are enabled on the site.
  • stupid_mode: Set to true if the system is running in database-less mode. Only true during installation and upgrade processes.
  • in_admin: Set to true if the current page is Special:Administration or an Admin: page.
  • sidebar_left: Set to true if there is any content for the left sidebar.
  • sidebar_right: Set to true if there is any content for the right sidebar.

Template syntax

The following patterns should be used inside of template files.

Variables

To insert the contents of a variable into the rendered HTML, use the format {VARIABLE_NAME}.

<title>{PAGE_NAME} &bull; {SITE_NAME}</title>

Conditionals (booleans)

You can check to see if a boolean is true using the format: <!-- BEGIN boolean_name -->Text to show if true<!-- END boolean_name -->

<!-- BEGIN user_logged_in -->
  Hello, {USERNAME}!
<!-- END user_logged_in -->

To specify alternate text to be shown if the boolean isn't true, use <!-- BEGINELSE boolean_name --> with a BEGIN block.

<!-- BEGIN user_logged_in -->
  Hello, {USERNAME}!
<!-- BEGINELSE user_logged_in -->
  Hello, guest! Please {LOGIN_LINK} or <a href="{CONTENTPATH}{NS_SPECIAL}Register">Register</a&gt.
<!-- END user_logged_in -->

You can also check to see if a boolean is NOT true using <!-- BEGINNOT boolean_name -->:

<!-- BEGINNOT user_logged_in -->
  Hello, guest! Please {LOGIN_LINK} or <a href="{CONTENTPATH}{NS_SPECIAL}Register">Register</a&gt.
<!-- END user_logged_in -->

BEGINELSE can also be used within BEGINNOT blocks.

<!-- BEGINNOT user_logged_in -->
  Hello, guest! Please {LOGIN_LINK} or <a href="{CONTENTPATH}{NS_SPECIAL}Register">Register</a&gt.
<!-- BEGINELSE user_logged_in -->
  Hello, {USERNAME}!
<!-- END user_logged_in -->

If you're not sure if a certain string value is set, you can check with <!-- IFSET variable_name -->:

<!-- IFSET USERNAME -->
  Hello, {USERNAME}!
<!-- END USERNAME -->

Furthermore, you can see if a certain plugin is loaded and enabled using <!-- IFPLUGIN PluginName.php -->:.

<!-- IFPLUGIN Newsboy.php -->
  This site has the NewsBoy portal plugin enabled.
<!-- END Newsboy.php -->

Both IFSET and IFPLUGIN support BEGINELSE as well.

<!-- IFPLUGIN Newsboy.php -->
  <!-- IFSET USERNAME -->
    Hello, {USERNAME}! Please check out our <a href="{CONTENTPATH}{NS_NEWSBOY}Portal{ADMIN_SID_AUTO}">Portal</a>.
  <!-- END USERNAME -->
<!-- END Newsboy.php -->

You can insert the contents of a System page (unprocessed) using <!-- SYSMSG page_id -->. The example below would include the contents of the page Enano:you_are_a_guest.

<!-- BEGINNOT user_logged_in -->
  <!-- SYSMSG you_are_a_guest -->
<!-- END user_logged_in -->

PHP can be used in template files using the normal <?php ?> tags. Please note that this is not a recommended way to include custom code, and certain templates will not accept PHP code because they are parsed client-side. See Section 5.1 for more details.

Finally, some template files (most notably elements.tpl and acledit.tpl) will actually contain several different but very small templates. These smaller templates are specified using VAR blocks. You can specify as many variables as you need in one template file, and gather them later using $template->extract_vars().

<!-- VAR var_name -->
  Contents of variable
<!-- ENDVAR var_name -->

That's about all there is to template syntax. Note that all logic tags are case-insensitive, but all variable and boolean names are case-sensitive.

Previous Section 5.2 - Template syntax Next
Introduction to Enano's theming system Up one level Creating your own theme
© 2007 Contributors. All content is under the GNU Free Documentation License.
Powered by Enano | Valid XHTML 1.1 | Valid CSS | Time: 0.07s