Plain PHP Snippets
In case you want to develop a new extension or use PHP in your templates, the collection of common code snippets below might help you getting started quickly.
Context and Pages
Getting the current page:
$Page = $Automad->Context->get();
Get any page by its local URL:
$Page = $Automad->getPage('/url');
Getting the page title or any other variable:
$title = $Page->get('title');
Shared Content
Getting the site's name or any other shared variable:
$sitename = $Automad->Shared->get('sitename');
Applying String Functions
Render a Markdown variable:
$text = $Page->get('text');
$output = \Automad\Core\Str::markdown($text);
Sanitize a variable:
$text = $Page->get('text');
$output = \Automad\Core\Str::sanitize($text);
More string functions can be found here.
Pagelists
To configure a pagelist and get the resulting page objects, you can do the following:
$Pagelist = $Automad->getPagelist();
$config = array('type' => 'children');
$Pagelist->config($config);
$pages = $Pagelist->getPages();
You can iterate the $pages
array as follows to get each page object:
foreach ($pages as $Page) {
echo '<p>' . $Page->get('title') . '</p>';
}