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

__construct(object $Automad, boolean $headless = false)

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

string
interpret(string $str, string $directory)

Process the full markup - variables, includes, methods and other constructs.

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".

string
resolveUrls(string $str, string $method, array $parameters = array())

Find and resolve URLs using the specified resolving method and parameters.

string
obfuscateEmails(string $str)

Obfuscate all stand-alone eMail addresses matched in $str.

string
render()

Render the current page.

Details

__construct(object $Automad, boolean $headless = false)

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

Parameters

object $Automad
boolean $headless

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.

Parameters

string $str
  • The string to be parsed
string $directory
  • The directory of the currently included file/template

Return Value

string The interpreted string

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".

Parameters

string $str

Return Value

string The processed string

string resolveUrls(string $str, string $method, array $parameters = array())

Find and resolve URLs using the specified resolving method and parameters.

Parameters

string $str
string $method
array $parameters

Return Value

string The processed string

string obfuscateEmails(string $str)

Obfuscate all stand-alone eMail addresses matched in $str.

Addresses in links are ignored.

Parameters

string $str

Return Value

string The processed string

string render()

Render the current page.

Return Value

string The fully rendered HTML for the current page.