Using the template keyword

Post Reply
keltis
Jr. Bludit
Posts: 1
Joined: Fri Jul 12, 2019 4:50 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 3635 times
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

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');
}
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
Andrei
Jr. Bludit
Posts: 4
Joined: Sat Sep 21, 2019 7:08 am
Been thanked: 1 time

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
Been thanked: 1 time

...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. :)
User avatar
cobber
Master Bludit
Posts: 78
Joined: Sun Feb 28, 2016 10:15 am
Location: Scotland
Has thanked: 21 times
Been thanked: 5 times

Andrei wrote: 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.
Perfect! exactly what I was looking for. Thanks
Post Reply