Automad
 All Classes Functions Variables Pages
Automad\Core\Template Class Reference

Public Member Functions

 __construct ($Automad)
 
 render ()
 

Private Member Functions

 addMetaTags ($str)
 
 callExtension ($name, $options)
 
 collectExtensionAssets ($extension)
 
 createExtensionAssetTags ($str)
 
 convertLegacy ($str)
 
 loadTemplate ($file)
 
 preProcessWrappingStatements ($str)
 
 processContent ($str, $isJsonString=false)
 
 processMarkup ($str, $directory)
 
 resolveUrls ($str)
 
 obfuscateEmails ($str)
 

Private Attributes

 $Automad
 
 $extensionAssets = array()
 
 $outerStatementMarker = '#'
 
 $Toolbox
 
 $template
 

Detailed Description

The Template class holds all methods to render the current page using a template file.

When render() is called, first the template file gets loaded by loadTemplate(). The output, basically the raw template HTML (including the generated HTML by PHP in the template file) gets stored in $output.

In a second step all statements and content in $output gets processed.

That way, it is possible that the template.php file can include HTML as well as PHP, while the "user-generated" content in the text files can not have any executable code (PHP). There are no "eval" functions needed, since all the PHP gets only included from the template files, which should not be edited by users anyway.

In a last step, all URLs within the generated HTML get resolved to be relative to the server's root (or absolute), before $output gets returned.

Author
Marc Anton Dahmen hello.nosp@m.@mar.nosp@m.cdahm.nosp@m.en.d.nosp@m.e
License
MIT license - http://automad.org/license

Definition at line 64 of file template.php.

Constructor & Destructor Documentation

Automad\Core\Template::__construct (   $Automad)

Define $Automad and $Page, check if the page gets redirected and get the template name.

Definition at line 106 of file template.php.

References Automad\Core\Debug\log(), and Automad\Core\Resolve\url().

Member Function Documentation

Automad\Core\Template::addMetaTags (   $str)
private

Add Meta tags to the head of $str.

Parameters
string$str
Returns
$str

Definition at line 134 of file template.php.

Automad\Core\Template::callExtension (   $name,
  $options 
)
private

Call an extension method.

Parameters
string$name
array$options
Returns
The returned content from the called method

Definition at line 151 of file template.php.

References Automad\Core\Debug\log().

Automad\Core\Template::collectExtensionAssets (   $extension)
private

Collect all assets (CSS & JS files) belonging to $extension and store them in $this->extensionAssets.

Parameters
string$extension

Definition at line 208 of file template.php.

References Automad\Core\Debug\log().

Automad\Core\Template::convertLegacy (   $str)
private

Convert legacy template syntax into the new syntax.

Parameters
string$str
Returns
The converted template

Definition at line 281 of file template.php.

Automad\Core\Template::createExtensionAssetTags (   $str)
private

Create the HTML tags for each file in $this->extensionAssets and prepend them to the closing </head> tag.

Parameters
string$str
Returns
$str

Definition at line 248 of file template.php.

References Automad\Core\Debug\log().

Automad\Core\Template::loadTemplate (   $file)
private

Load and buffer a template file and return its content as string. The Automad object gets passed as parameter to be available for all plain PHP within the included file. This is basically the base method to load a template without parsing the Automad markup. It just gets the parsed PHP content.

Before returning the markup, the old Automad template syntax gets translated into the new syntax and all comments {* ... *} get stripped.

Note that even when the it is possible to use plain PHP in a template file, all that code will be parsed first when buffering, before any of the Automad markup is getting parsed. That also means, that is not possible to make plain PHP code really interact with any of the Automad placeholder markup.

Parameters
string$file
Returns
the buffered output

Definition at line 305 of file template.php.

Automad\Core\Template::obfuscateEmails (   $str)
private

Obfuscate all eMail addresses matched in $str.

Parameters
string$str
Returns
$str

Definition at line 803 of file template.php.

Automad\Core\Template::preProcessWrappingStatements (   $str)
private

Preprocess recursive statements to identify the top-level (outer) statements within a parsed string.

Parameters
$str
Returns
The preprocessed $str where all outer opening statement delimiters get an additional marker appended.

Definition at line 333 of file template.php.

Automad\Core\Template::processContent (   $str,
  $isJsonString = false 
)
private

Process variables only.

Find and replace all variables within $str with values from either the context page data array or, if not defined there, from the site data array, from the system variables array (only those starting with ":") or from the $_GET array (only those starting with a "?").

When matching {[ var ]} the parser will check first the page data and then the site data. When matching {[ :var ]}, the parser will only check the system variables array. When matching {[ ?var ]}, the parser will only check the $_GET array.

By first checking the page data, basically all site data variables can be easily overridden by a page. Optionally all values can be parsed as "JSON safe", by escaping all quotes and wrapping variable is quotes when needed. In case a variable is used as an option value for a method and is not part of a string, that variable doesn't need to be wrapped in double quotes to work within the JSON string - the double quotes get added automatically.

Parameters
string$str
boolean$isJsonString
Returns
The processed $str

Definition at line 391 of file template.php.

References Automad\Core\Automad\getValue(), and Automad\Core\Parse\jsonEscape().

Automad\Core\Template::processMarkup (   $str,
  $directory 
)
private

Inside a "foreach in pagelist" loop the context changes with each iteration and the active page in the loop becomes the current page. Therefore all variables of the active page in the loop can be accessed using the standard template syntax like $( var ). Inside other loops there are special system variables available to be used within a snippet: {[ :filter ]}, {[ :tag ]}, {[ :file ]} and {[ :basename ]} and the index {[ :i ]}.

Parameters
string$str- The string to be parsed
string$directory- The directory of the currently included file/template
Returns
the processed string

Definition at line 453 of file template.php.

References Automad\Core\Parse\jsonOptions(), and Automad\Core\Debug\log().

Automad\Core\Template::render ( )

Render the current page.

Returns
The fully rendered HTML for the current page.

Definition at line 826 of file template.php.

References Automad\Core\Debug\log().

Automad\Core\Template::resolveUrls (   $str)
private

Find all links/URLs in $str and resolve the matches according to their type.

Parameters
string$str
Returns
$str

Definition at line 777 of file template.php.

Member Data Documentation

Automad\Core\Template::$Automad
private

The Automad object.

Definition at line 71 of file template.php.

Automad\Core\Template::$extensionAssets = array()
private

Multidimensional array of collected extension assets grouped by type (CSS/JS).

Definition at line 78 of file template.php.

Automad\Core\Template::$outerStatementMarker = '#'
private

The outer statement marker helps to distinguish all outer wrapping statements from the inner statements.

Definition at line 85 of file template.php.

Automad\Core\Template::$template
private

The template file for the current page.

Definition at line 99 of file template.php.

Automad\Core\Template::$Toolbox
private

The Toolbox object.

Definition at line 92 of file template.php.


The documentation for this class was generated from the following file: