Take a look at page.php
from the Timber Starter Theme:
<?php
$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
Timber::render( array( 'page-' . $post->post_name . '.twig', 'page.twig' ), $context );
The Timber::render
method on the last line loads page.twig
as the default page template. However, Timber also checks for any twig files with the page-
prefix followed by the name of a post (or in this case a page) with the code:
'page-' . $post->post_name . '.twig'
I really like this technique for handling custom pages because it prevents us from having to create custom page php files. This is especially helpful on sites with many pages.
If you want the page title to be "Page Product All" then your twig file will have to be page-page-product-all.twig
. I sort of have a feeling you just want the page to be called "Product All" so in that case the twig file would remain page-product-all.twig
and you will have to create a page called "Product All"
Now add a simple <h1>hello world</h1>
to page-product-all.twig (I prefer <h1>hi mom!</h1>
), preview the Product All page and voila. Custom page templates with Timber.