Skip to content

Template Development

Brian McCoy edited this page Feb 23, 2018 · 1 revision
  • By default the header, footer and homepage (front-page.php) are set up for you.
  • Every template, post type, etc. should be set up with a PHP file and a Twig file. For example if you have template-about.php you would have views/template-about.twig
  • The PHP file should have a class that extends the Core_Template class. Example: class Template_About extends Core_Template. Whatever the class name is will be what it tries to load from the views directory. In this example it'd look for template-about.twig. You can overwrite this by defining a template_file method in your class. See header.php for an example.
  • Any methods defined in your class will be returned to the Twig template as data. For instance if you have a method hero that returns an array you could access it in your Twig file like {{hero.heading}} if you have a key in your array called heading. I recommend having a method for each section of the template returning relevant data for that section.
  • The Core_Template class also supplies your Twig template with some commonly accessed data: {{constants.blogURL}}, {{constants.templateURL}}, {{constants.templateDir}}, {{constants.mediaURL}}

Clone this wiki locally