Page 1 of 1

Using the template keyword

Posted: Fri Jul 12, 2019 4:55 pm
by keltis
Hi everybody,

under `Content > Options > Advanced` you can specify a template name, as shown in the screenshot.

Do I need to manually check for the template name using php or is there a build-in support for templates already?

Best regards
Thomas

Sreenshot:
Screenshot 2019-07-12 at 16.51.46.png
Screenshot 2019-07-12 at 16.51.46.png (24.42 KiB) Viewed 107 times

Re: Using the template keyword

Posted: Fri Jul 12, 2019 8:17 pm
by Edi
This function is not yet implemented.

But you can select a template with an if condition in the file index.php of the theme.

If you have for example a template for a page with contact information (with the slug "contact") you can use:

Code: Select all

if ($WHERE_AM_I == 'page') {
   if ($page->slug() == 'contact') {
      include(THEME_DIR_PHP.'contact.php');
   else {
      include(THEME_DIR_PHP.'page.php');
      }
} else {
   include(THEME_DIR_PHP.'home.php');
}

Re: Using the template keyword

Posted: Sat Sep 21, 2019 10:05 am
by Andrei
Hi,

I made it to work my way using a Custom Field called "template", and checking the value inside index.php with two basic "if" statements.

Code: Select all

<?php
            if ($page->custom('template')) {   
         
                    // If a custom template is specified 
                    if ($WHERE_AM_I=='page') {
                        include(THEME_DIR_PHP.$page->custom('template').'.php');
                    } else {
                        include(THEME_DIR_PHP.'home.php');
                    }   
                 
            } else {    
     
                   // If not
                    if ($WHERE_AM_I=='page') {
                        include(THEME_DIR_PHP.'page.php');
                    } else {
                        include(THEME_DIR_PHP.'home.php');
                    }    
             
            }      
?>
Then you just need to make the whatever specific template you need and don't forget to put the right name in the custom field.

There are maybe other ways to do it, but that one works and hope it helps.