Using the template keyword
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:
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:
- 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:
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
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.
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.
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');
}
}
?>
There are maybe other ways to do it, but that one works and hope it helps.
...even simpler after all:
Just checked if dealing with an actual "page": and include the page.php partial, otherwise just load something like article.php for a more specific layout.
Just checked if dealing with an actual "page":
Code: Select all
if ($page->type() == "static")
- cobber
- Master Bludit
- Posts: 78
- Joined: Sun Feb 28, 2016 10:15 am
- Location: Scotland
- Has thanked: 21 times
- Been thanked: 5 times
Perfect! exactly what I was looking for. ThanksAndrei 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.
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.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'); } } ?>
There are maybe other ways to do it, but that one works and hope it helps.