• ♡ Sponsor

    Using Extensions

    #Extension #Method #PHP #Pipe #Statement

    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.

    <# Generic extension. #>
    <@ namespace/name { options } @>
    <# Custom pipe function. #>
    @{ variable | namespace/name }
    

    Find out more about developing extensions here.

    Example

    A good example to visualize how to use extensions is the MetaTag extension. As mentioned above the basic syntax is similar to Toolbox methods.

    <head>
    <@ Automad/MetaTags { 
        description: @{ metaDescription | def(@{ text | stripTags }) },
        ogTitle: @{ ogTitle | def('@{ sitename } / @{ title }') },
        ogDescription: @{ ogDescription | def(@{ text | stripTags }) },
        ogType: 'website',
        ogImage: @{ ogImage | def('/shared/og*.png') }
    } @>
    <# Add some CSS or JS tags here ... #>
    </head>
    

    Related

    Template Language  ⁄
    Pipe — Template Language

    A pipe | allows for using the value of a variable to be the input value for a function. It is also possible to chain multiple functions together, so that the output of one function is used as input for the next one. Therefore a pipe can be used to modify the value of a variable ...

    Template Language  ⁄
    Toolbox — Template Language

    The Toolbox provides a collection of essential functions for templates. While some are just convenient shorthand functions for more complex statements, others provide the main interface to interact with objects, create redirects and work with query strings.

    Template Language  ⁄
    Control Structures — Template Language

    As in other languages, control structures in Automad are statements that dynamically determine the flow of an application or website based on evaluating content or variables. Automad knows four different statements to control the flow of the application: for, foreach, if and ...

    Template Language  ⁄
    Snippets — Template Language

    The snippet statement allows for defining reusable code snippets and is therefore also the basis for any kind of recursion in Automad. A snippet always inherits the context of the calling code. To use a snippet, it is enough to put the snippet's name in statement delimiters.

    Template Language  ⁄
    Includes — Template Language

    In many cases, different templates across a theme use recurring components such as a header, a navbar or a footer. Those elements can be stored in separate files and included whenever needed. To include such an external snippet, simply wrap its path relative to the current file ...

    Building Themes  ⁄
    Plain PHP — Building Themes

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

    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  ⁄
    Publishing Packages — Developer Guide

    Automad uses Composer as dependency manager. Therefore packages can be made public by submitting them as Composer packages to the Packagist website. Published Automad packages also automatically appear in the package browser. The process of releasing a package is basically the ...

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

    • Automad
    • Developer Guide
    • Building Themes
    • Template Language
    • Using Extensions
    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 ←
  • Template Language
  • Variables →
  • Pipe →
  • Toolbox →
  • Objects →
  • Control Structures →
  • Snippets
  • Includes
  • Inheritance
  • Using Extensions
  • Recursive Navigations
  • Working with Images
  • Multilingual Content