Using the template keyword

Post Reply
keltis
Jr. Bludit
Posts: 1
Joined: Fri Jul 12, 2019 4:50 pm

Fri Jul 12, 2019 4:55 pm

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 232 times
User avatar
Edi
Site Admin
Posts: 1624
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

Fri Jul 12, 2019 8:17 pm

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');
}
Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
Andrei
Jr. Bludit
Posts: 4
Joined: Sat Sep 21, 2019 7:08 am

Sat Sep 21, 2019 10:05 am

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.
Andrei
Jr. Bludit
Posts: 4
Joined: Sat Sep 21, 2019 7:08 am

Sun Sep 29, 2019 5:32 am

...even simpler after all:
Just checked if dealing with an actual "page":

Code: Select all

if ($page->type() == "static")
and include the page.php partial, otherwise just load something like article.php for a more specific layout. :)
Post Reply