new Template - jcobban/Genealogy GitHub Wiki

new Template($filename)

Up: class Template

The constructor for an instance of Template has one parameter:

parameter Description
$filename Is a String. Typically it is the the name of the document containing the top or common portion of the page. This may be either the name of a file in the server's file system or the URL of a web-page. If the string contains a less-than '<' or a dollar sign '$' then the contents are assumed to be the document to be processed rather than the document name.

Examples:

    $ll              = 'en';
    $template        = new \Templating\Template("$document_root/templates/page$ll.html");

This document contains those portions of the presentation which are represent common look and feel of the site. This file contains the standard HTML head tag and the page header and footer portions for the genealogy web-site. It defines a substitution marker 'MAIN' for which each application script will identify an HTML template file containing the body content of the page using the method $template->includeSub.

    $template        = new \Templating\Template("http://www.automatedgenealogy.com/census11/District.jsp?did={$this->district}");

This loads a web-page and parses it as an HTML document.

        $dataRow            = $template['dataRow'];
        $dataHtml           = $dataRow->innerHTML();
        $data               = '';
	foreach($result as $row)
        {
            $dtemplate          = new Template($dataHtml);
            ... update $dtemplate
            $data               .= $dtemplate->compile();
        }	
        $dataRow->update($data);

This represents a common situation where a portion of one HTML document is extracted and used to create a template for a repeated portion of the generated page. Since the string $dataHtml contains a less-than '<' character it is treated as a block of HTML rather than as a document name.

Next: $template->customization()