Automad supports plain PHP in template files. However, variables used in plain PHP blocks will not show up automatically in the dashboard and mixing PHP with Automad's template engine should be done carefully. Therefore it is not recommended to use plain PHP in normal templates. Missing functionality should always be implemented as an extension, where the plain PHP code is nicely wrapped into an Automad statement to integrate well with the rest of the template in use. In case you still prefer to write plain PHP templates, please read on and also check out this tutorial.
An instance of the Automad class is always available within any template and is called
$Automad. That object stores all your site's data and pages.
$Automad object is a superior collection of many smaller units, the page objetcs.
Getting the current page object:
$Page = $Automad->Context->get();
Other pages can be accessed by their URL. An URL is always the main reference to a page in Automad. Note that those URLs are always relative to Automad's homepage, represented by a single slash
$Page = $Automad->getPage('/url');
$Page object stores now all data related to the current context.
The best way to get familiar with page objects is to do a simple:
To get any data from the
$Page object you can use the
<h1><?php echo $Page->get('title'); ?></h1>
You can get the pagelist object like this:
$Pagelist = $Automad->getPagelist();
To configure the object, use the
$Pagelist->config(array( 'type' => 'children', 'sort' => Str::def(Parse::query('sort'), 'date desc') ));
There is also a full API reference for a more detailed documentation on all classes and their methods. The most important classes to start with are: