• ♡ Sponsor

    Plain PHP

    #PHP #Theme

    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.

    Check out the Cheat Sheets for working with plain PHP templates.

    Introduction

    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.
    Basically the $Automad object is a superior collection of many smaller units, the page objetcs.

    Getting Pages

    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');
    

    The $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:

    print_r($Page);
    

    To get any data from the $Page object you can use the get() method:

    <h1><?php echo $Page->get('title'); ?></h1>
    

    Pagelists

    You can get the pagelist object like this:

    $Pagelist = $Automad->getPagelist();
    

    To configure the object, use the config() method:

    $Pagelist->config(array(        
        'type' => 'children',
        'sort' => Str::def(Parse::query('sort'), 'date desc')
    ));
    

    API Reference

    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:

    • \Automad\Core\Automad
    • \Automad\Core\Pagelist
    • \Automad\Core\Str
    • \Automad\Core\Toolbox
    • \Automad\Core\Parse
    • \Automad\Core\Image

    Related

    Developer Guide  ⁄
    Building Themes — Developer Guide

    Themes are an essential part of a content management system. They define the way your content is presented to the visitors of your website. Automad's flexible and intuitive template language enables also inexperienced developers or beginners to create themes and templates on ...

    Building Themes  ⁄
    theme.json — Building Themes

    Every theme needs a theme.json to work. As mentioned before, all subdirectories of the packages directory containing a theme.json side by side with at least one template are to be considered as valid themes. Please see the list below for all required fields.

    Building Themes  ⁄
    Template Language — Building Themes

    Automad's template language provides a flexible and safe way to render content dynamically. In contrast to other generic template engines, the Automad core functions are integrated into the engine. That includes such things as image processing as well as a the access to an even ...

    Template Language  ⁄
    Using Extensions — Template Language

    Extensions provide a convenient way of turning custom PHP code into Automad statements. Besides the fact that extensions have to be called by their names including their namespace, the syntax is the same as for Toolbox or pipe functions.

    Building Themes  ⁄
    Block Layouts — Building Themes

    Aside from just stacking blocks on top of each other, Automad's block editor provides some handy features to create flexible layout directly in the block editor. It is possible to stretch a block to the full with of the parent container to make it stand out as well as to arrange ...

    Building Themes  ⁄
    Customizing Blocks — Building Themes

    Most of the blocks only consist of pure HTML tags without classes and just inherit theme styles when being displayed. However the default styling of more complex blocks like the mail form or the gallery block might not be matching a theme out of the box. You can use CSS custom ...

    Developer Guide  ⁄
    Developing Extensions — Developer Guide

    The extension interface provides a convenient way of extending Automad's core functionality with custom PHP code while still offering Automad's template syntax. There are basically two types of template language extensions: generic extensions and custom pipe functions. Check out ...

    Developing Extensions  ⁄
    Generic Extensions — Developing Extensions

    In case you are missing any advanced feature while developing themes using Automad's template language, you are able to implement that functionality as a generic extension written in plain PHP.

    Developing Extensions  ⁄
    Custom Pipe Functions — Developing Extensions

    Automad provides already some basic string manipulation functions to be used with the pipe operator. However, in some cases it my be necessary to use a custom function to modify the content of a variable. Custom pipe functions can be written in plain PHP. Thier basic setup is ...

    Developer Guide  ⁄
    Cheat Sheets — Developer Guide

    In case you prefer to start developing a theme or extension without reading the full documention, the cheat sheets below are a good point to start. In addition to this page there is also the theme skeleton package available to help you getting started.

    Cheat Sheets  ⁄
    Useful Template Snippets — Cheat Sheets

    Find below a collection of useful snippets for common tasks using Automad's template language.

    Cheat Sheets  ⁄
    Plain PHP Snippets — Cheat Sheets

    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.

    Cheat Sheets  ⁄
    Creating Theme Packages — Cheat Sheets

    This guide describes step by step the workflow of setting up and publish a new theme. It assumes you're familiar with Visual Code Studio and working on a system with a Bash shell or similar — like macOS or Linux.

    • Automad
    • Developer Guide
    • Building Themes
    • Plain PHP
    Discuss
    Packages
    Release Notes
    Support
    Terms of Use
      Become a Sponsor
      GitHub
      Twitter
      Facebook
      Instagram
      2013-2022 by Marc Anton Dahmen
    Released under the MIT license

    A faceless machine, creating one's portrait in the internet.
  • Automad
  • Getting Started
  • System
  • User Guide
  • Developer Guide
  • Headless Mode
  • Discuss
  • Packages
  • Developer Guide ←
  • Building Themes
  • theme.json
  • Template Language →
  • Block Layouts
  • Customizing Blocks
  • Plain PHP