Copy environment

Templates

Please read the WordPress docs for templates.

Each WordPress template will use one of the templates defined in gotoAndPlay/Templates folder.

It will call render function that is inherited from the parent.

Creating a template

When creating a template usually you need to create at least two files.

  • template-[name].php is the file for WordPress.
  • gotoAndPlay/Template/[name].php template class which will be used to pass all data to twig.

In this example we create a simple playground template.

<?php
/*
 * Template name: Playground
 */
gotoAndPlay\Templates\Playground::render();

And also the corresponding class with a simple get method.

<?php
namespace gotoAndPlay\Templates;

use gotoAndCore\Models\Page;

class Playground extends Page {
    /* sets template class connection to WordPress template */
    protected static $templateName = 'template-playground.php';

    public function getPlayers() {
        /* get_field function comes from third-party plugin Advanced Custom Fields or ACF in-short */
        return get_field('players', $this->ID);
    }

    /* is used to determine which view should be rendered from styleguide */
    protected function getView() {
        return '@view-playground';
    }
}