4 Creating Portal Templates
Joe Prochazka edytuje tę stronę 2016-02-26 13:20:13 -05:00

Contents

Areas

Areas are snippets of HTML and template code which are defined within and taken from the page template and placed in a specified point within the master template.

Master Template

The master template contains the HTML in which areas defined in the page template are inserted. When a template is processed areas contained within the corresponding page template are inserted into the master template. There is no restriction on where the area tags are placed within the master template. Also there is no limit to the amount of areas allowed to be inserted into the master template from the page template.

Page area to master template illustration.

To define the place or places in which areas taken from the page template are to be located within the master template an area tag will need to be positioned somewhere within the master template. The master template area tag should look like the following with "name" being the name of the area taken from the page template to be placed within the master template.

{area:name}

Master templates are able to use all the functionality available to page templates. The master template also has full access template system data as well as data passed to the template system by the page's PHP file. Specifics on the data available will be covered later on in this documentation.

At this time keep in mind when displaying data generated by the page's PHP file make sure that that data is available from all page PHP files and is not specific to only certain page templates. A more robust {if ...} statement will be made available in the future which can be used to check for the existence of data which should help overcome this short coming.

Page Templates

Page templates contain areas which are inserted into the master template where a corresponding area tag is located when a page is rendered. All page data passed from the corresponding PHP file is available for use within the page template. As stated earlier a page template must contain all areas defined in the master template.

Page template.

Area tags containing content are formatted as follows with "name" being the name of the area, "..." the content contained within the area, and "{/area}" marking the end of that area's content.

{area:name} ... {/area}

Empty tags need to be formatted like so with "name" being the name of the area.

{area:name/}

Page templates have access to all data made available by the template system as well as the corresponding PHP file. Specifics on the data available will be covered later on in this documentation.

Variables

The template system is capable of replacing certain tags with variables containing data stored within the system's data stores such as settings, data made available by the template system itself, as well as data passed to the template system from the corresponding PHP page. Specific tags will need to be used depending on the type of data you wish to display.

Settings

In order to display or use data stored as an application setting you will need to use the setting tag. Using the setting tag will pull data stored within settings.xml by replacing "name" with the name of the setting in the following example and allow you to display the setting within the rendered page. A list of available settings is available later on in this documentation.

{setting:name}

Always be careful when displaying settings to ensure you are not displaying ones which may display data you do not wish displayed to the public and/or may result in a security risk if this information was made know to the public.

Settings can also be queried and used within statements such as ifs. This is useful for showing or not showing sections of a template depending on what a setting is set to. In this case the setting is asked for using basically the same format as above minus the brackets. The following is an example of using a setting to show or hide a link depending on the "enableBlog" setting's value.

{if setting:enableBlog eq TRUE}<li id="blog-link"><a href="/blog.php">Blog</a></li>{/if}

Page Variables

Page variables contain data passed to the template system vis the requested pages PHP file. Page data available to one page generally will not be the same as that made available to another. That being said thing of page variables as variables specific to a single template. All available page variables listed under the page they are available to are listed later on in this document.

Page variables work the same as settings variables. The only difference being the word "page" is displayed before the "name" of the variable being called for. The following is an example of how to display a page variable where name is the name of the variable to be displayed.

{page:name}

Some data passed as a page variable may be in the form of an array. These types of data are only useful for use in loops and are not meant to be displayed directly as shown above. The list of page variables found later in this document will outline which are arrays and which are not.

As with settings variables page variables can be used in conditional statements such as ifs or for loops. The following is an example of a for loop using a page variable as an upper limit.

{for pageNumber eq 1 to page:pageLinks}
    <li><a href="blog.php?page={pageNumber}">{pageNumber}</a></li>
{/for}

Statements

The template system is able to handle logic inserted into a template by the designer in much the same way most programming languages allow. Currently simple if statements, foreach loops, and for loops are supported.

If

An if statement uses a conditional statement which if proven true performs an operation. Currently the following operators are available when constructing your conditional statement.

  • "eq" which stands for equals.
  • "neq" standing for not equal.

The following is an example of an if statement which displays a link to the blog homepage if the enableBlog setting is set to TRUE. If enableBlog setting is not set to true the link is not displayed.

{if setting:enableBlog eq TRUE}<li id="blog-link"><a href="/blog.php">Blog</a></li>{/if}

If statements can also include an else clause which displays the contents between the {else} tag and the [/if} tag if the if the if statement is determined to be not true. And example of an if statement with an else clause is as follows.

{if setting:networkInterface eq eth0}
<div class="col-md-6 text-center">
    <a id ="system-eth0_bandwidth-link" href="#">
        <img id="system-eth0_bandwidth-image" class="img-responsive" src="#" alt="Bandwidth Usage (eth0)">
    </a>
</div>
{else}
<div class="col-md-6 text-center">
    <a id ="system-wlan0_bandwidth-link" href="#">
        <img id="system-wlan0_bandwidth-image" class="img-responsive" src="#" alt="Bandwidth Usage (wlan0)">
    </a>
</div>
{/if}

Foreach

A foreach loops allows you to iterate through a collection of data. Generally these collections are in the form of arrays passed to the template system as page variables from the relating PHP file. The value for a specific key contained within the item currently being processed by the foreach loop can be displayed using the following tag format.

{item->key}

The following is an example of a foreach statement which loops through an array containing the data making up a collection of blog posts and inserts this data in it's proper place within the HTML. It will continue to do so making copies of the outlined HTML with said data inserted until it has read all data contained within the array.

{foreach page:blogPosts as post}
<h2><a href="post.php?title={post->title}">{post->title}</a></h2>
<p>Posted <strong>{post->date}</strong> by <strong>{post->author}</strong>.</p>
<div>{post->contents}</div>
{/foreach}

For

A for loop is used to specify iteration. Generally it is used to repeat something until a counter has reached a specified stopping point. The pagination feature used by the default template when visiting the blog page is a prime example of it's usage. The following is a snippet taken from the default template showing the usage of a for statement.

<ul class="pagination">
    {for pageNumber eq 1 to page:pageLinks}
    <li><a href="blog.php?page={pageNumber}">{pageNumber}</a></li>
    {/for}
</ul>

Comments

Template designers can place comments displaying information about their templates and/or to make notes for future reference directly within any template file. These comments will be removed when the template is rendered as to not send this extra data out to visitors to the site. To add a comment to your template starting at the beginning of the commend add {* and at the end *}. Comments can be a single line or multiple lines. The following is an example of both.

{* This is a single line comment... *}

{*
This is a comment
spread out over multiple lines...
*}

Available Variables

The following is a list of all variables made available including settings, via the PHP files related to the page being requests, or via the template system. As well as listing the variable a brief description is provided as well.

Settings Variables

  • siteName [string] The name of the site as set in the administration backend.
  • template [string] The name of the template currently used.
  • defaultPage [string] The page to which visitors are directed when visiting the root URL.
  • enableBlog [boolean] Whether or not the blog link should be displayed.
  • enableInfo [boolean] Whether or not the system information link should be displayed.
  • enableGraphs [boolean] Whether or not the performance graphs link should be displayed.
  • enableDump1090 [boolean] Whether or not the live dump1090 map link should be displayed.
  • enableDump978 [boolean] Whether or not the live dump978 map link should be displayed.
  • enablePfclient [boolean] Whether or not the Planefinder ADS-B Client web interface link should be displayed.
  • enableFlightAwareLink [boolean] Whether or not the FlightAware stats page link should be displayed.
  • enablePlaneFinderLink [boolean] Whether or not the Planefinder stats page link should be displayed.
  • enableFlightRadar24Link [boolean] Whether or not the FlightRadar24 stats page link should be displayed.
  • enableAdsbExchangeLink [boolean] Whether or not the ADS-B Exchange link should be displayed.
  • flightAwareLogin [string] The FlightAware login associated to this receiver.
  • flightAwareSite [string] The FlightAware site number associated to this receiver.
  • planeFinderReceiver [string] The Planefinder receiver ID for this receiver.
  • flightRader24Id [string] The page ID for the Flightradar24 stats page for this receiver.
  • measurementRange [string] The type of measurement to be used when displaying range.
  • measurementTemperature [string] The type of measurement to be used when displaying temperature.
  • networkInterface [string] The name of the selected primary network interface.

Page Variables

For easier reference the page variables are broken down by the page they pertain to.

blog.php

  • title [string] The title of the page being accessed.
  • blogPosts [array] An array containing the blog posts to be displayed on this page.
  • pageLinks [integer] The number of page links to be created for pagination.

dump1090.php

  • title [string] The title of the page being accessed.

dump978.php

  • title [string] The title of the page being accessed.

graphs.php

  • title [string] The title of the page being accessed.

post.php

  • title [string] The title of the page being accessed. (In this case the title of the post.)
  • postTitle [string] The title of the post.
  • postdate [string] The date the post was created.
  • postAuthor [string] The post authors name.
  • postContents [string] The contents of the post.

system.php

  • title [string] The title of the page being accessed.

  • flightAwareLink [string] Generates a link to the receiver's FlightAware stats page.

  • planeFinderLink [string] Generates a link to the receiver's Planefinder stats page.

  • flightRader24Link [string] Generates a link to the receiver's FlightRadar24 stats page.## Template Variables_

  • adsbExchangeLink [string] Generates a link to the ADS-B Exchange website.

  • pageId [string] Outputs the page accessed minus the extension. (used mainly for CSS purposes.)