FtTemplate::displayBegin - jcobban/Genealogy GitHub Wiki
#$template->displayBegin()
Up: class FtTemplate
This method is called after the raw template files have been assembled but before any of the update logic is performed. The sample version for the Family Tree web-site defines a set of common substitution values based upon the environment and copies the contents of a <div id='breadcrumbs'>
from the template into the hidden division which is displayed when the user clicks on the menu button. Specifically this routine sets the value of the global substitution ‘BREADCRUMBS' which insertion point appears in the master page an dialog templates.
$crumbTag = $template['breadcrumbs'];
$breadcrumbs = $crumbTag->innerHTML();
$this->set('BREADCRUMBS', $breadcrumbs, true);
$crumbTag->update(null); // delete the template tag
This has the effect of extracting the contents of the tag with id=”breadcrumbs”, substituting any global substitutions, applying any specific tag updates, defined by calls to $templateTag‑>update
, that match tags within the contents, and ensuring that any such tag updates are not applied again when the template is generated. In particular this permits the page script to control which breadcrumb entries are displayed based upon input parameters to the script. For example the script BlogPost.php does the following:
if ($parentblogid == 0)
$template['parentBlog']‑>update(null);
else
$template['parentBlog']‑>update(array('parentblogid' => $parentblogid));
to manipulate a tag that looks like the following which is within the tag with id=”breadcrumbs”:
<span id="parentBlog">
<a href="BlogPost.php?table=Blogs&blogid=$parentblogid">
Blog $parentblogid
</a>:
</span>
The template design guide requires that within the <h1>
tag for the page there should be a hyper-link to a page which describes the overall functionality of the page. This looks like:
<span class='right'>
<a href='/database/ScriptNameHelpen.html' target='help'>? Help</a>
</span>
The contents of this <span>
tag is appended as a line in the menu displayed by the menu button, and the <span>
tag is deleted.
If the current template is expanding a dialog there is no separate header section. Instead the menu button is present within the <main>
section of the <body>
. For a dialog the
is presented immediately to the right of the menu button for compactness. To achieve this FtTemplate::displayBegin
removes the <h1>
tag that is present in the script-specific template and moves its contents.
To support script specific CSS the common page and dialog templates define a <link id=”otherStylesheets”>
in the <head>
section which looks like:
<link rel='stylesheet' type='text/css' href='$filename.css' id="otherStylesheets">
This permits the script to add additional style-sheets by, for example:
$template['otherStylesheets']‑>update(array('filename' => '/Account'));
If the value assigned to ‘otherStylesheets' is an array of arrays then multiple application-specific stylesheets can be defined. Note that the file type is not included in the value of the substitution ‘filename' because it must be .css
. If no value is assigned for ‘otherStylesheets' by the script then the tag ‘otherStylesheets' is removed from the header.
Next: $template->displayEnd()