autoloading - maxcal/Twigpress GitHub Wiki

#Autoloading

Twigpress can mimic Worpress the Wordpress template inheritance cascade but load twig files instead. This is useful if you intend need a drop in PHP replacement.

The theme only needs a index.php file which tells Twigpress to mimic Worpress normal template inheritance and load the appropriate Twig template.

// /themes/yourTheme/index.php
$Twigpress->registerGlobalFunctions();
echo $Twigpress->autoDisplay($wp_query);

A query for:

 example.org/?author=1

Would do the following lookup:

  1. Is there a PHP file with higher specificity? If so let it have the query (this is done by Wordpress).

    1. author-max.php
    2. author-1.php
    3. author.php
    4. index.php
  2. Twigpress uses the following cascade to look in its path for templates:

    1. author-max.html.twig
    2. author-max.twig
    3. author-1.html.twig
    4. author-1.twig
    5. author.html.twig
    6. author.twig
    7. index.html.twig
    8. index.twig
    9. error