View
class View (View source)
The View class holds all methods to render the current page using a template file.
When render() is called, first the template file gets loaded. 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.
Properties
$extensionAssets | Multidimensional array of collected extension assets grouped by type (CSS/JS). |
Methods
Define $Automad and $Page, check if the page gets redirected and get the template name.
Merge given assets with $this->extensionAssets.
Process the full markup - variables, includes, methods and other constructs.
Resize any image in the output in case it has a specified size as query string like for example "/shared/image.jpg?200x200".
Find and resolve URLs using the specified resolving method and parameters.
Obfuscate all stand-alone eMail addresses matched in $str.
Render the current page.
Details
at line 131
__construct(object $Automad, boolean $headless = false)
Define $Automad and $Page, check if the page gets redirected and get the template name.
at line 217
mergeExtensionAssets(array $assets)
Merge given assets with $this->extensionAssets.
The $this->extensionAssets array consists of two sub-arrays - $this->extensionAssets['.css'] and $this->extensionAssets['.js']. Therefore the $assets parameter must have the same structure to be merged successfully.
at line 544
string
interpret(string $str, string $directory)
Process the full markup - variables, includes, methods and other constructs.
Replace variable keys with its values, call Toolbox methods, call Extensions, execute statements (with, loops and conditions) and include template elements recursively. For example <@ file.php @>, <@ method { options } @>, <@ foreach in ... @> ... <@ end @> or <@ if @{var} @> ... <@ else @> ... <@ end @>.
With and foreach:
Pages: Within a <@ with "/url" @> statement or a <@ foreach in pagelist @> loop the context changes (with each iteration in loops) and the active page becomes the current page. Therefore all variables of that active page inside the with statements or loop can simply be accessed using the standard template syntax like @{var}.
Files: The <@ with "image.jpg" {options} @> statement and the <@ foreach in filelist {options} @> or <@ foreach in "*.jpg" {options} @> loop make data associated with files accessible. The following runtime vars can be used inside: - @{:basename} - @{:file} - @{:width} - @{:height} - @{:fileResized} - @{:widthResized} - @{:heightResized} - @{:caption}
Tags/Filters: Inside other foreach loops, the following runtime variables can be used within a snippet: - @{:filter} - @{:tag}
All loops also generate an index @{:i} for each elements in the array.
at line 978
string
resizeImages(string $str)
Resize any image in the output in case it has a specified size as query string like for example "/shared/image.jpg?200x200".
at line 1005
string
resolveUrls(string $str, string $method, array $parameters = array())
Find and resolve URLs using the specified resolving method and parameters.
at line 1080
string
obfuscateEmails(string $str)
Obfuscate all stand-alone eMail addresses matched in $str.
Addresses in links are ignored. In headless mode, obfuscation is disabled.
at line 1125
string
render()
Render the current page.