Custom template for the pages

User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 55 times
Been thanked: 78 times
Contact:

bnetz wrote: Wed Jul 14, 2021 6:15 pm Now it's some months later - is it planned that this function is coming to life maybe in Bludit 4.x?
I have not seen this feature.
The recent solution is not really working for me because I want to use a special template for many pages. (Perhaps a solution could be to use the php-switch Edi described for a category, but I don't know how to implement this …)
What exactly do you want to do?
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
novafacile
Master Bludit
Posts: 113
Joined: Sat Oct 06, 2018 4:47 pm
Has thanked: 41 times
Been thanked: 11 times
Contact:

The recent solution is not really working for me because I want to use a special template for many pages. (Perhaps a solution could be to use the php-switch Edi described for a category, but I don't know how to implement this …)
There is a possibility to use the template setting for the pages and also for the categories. The value is stored in the page/category, you just have to add it to the theme. I use it productively for a theme of mine.

The variables are called:
  • $page->template()
  • $page->categoryTemplate()
I have built the distinction in the index.php of the theme:

Code: Select all

switch ($WHERE_AM_I) {
  case 'page':
    if ($page->template()) {
      include(THEME_DIR_PHP.$page->template().'.php');
    } elseif($page->categoryTemplate()){
      include(THEME_DIR_PHP.$page->categoryTemplate().'.php');
    } else {
      include(THEME_DIR_PHP.'page.php');
    }
  break;
  default:
    include(THEME_DIR_PHP.'home.php');
  break;
}
The only limitation is that you have to enter the template exactly written correctly by hand. There is no selection option. To avoid errors I use therefore for this among other things the categories. Once set in the config, the appropriate template is always used. But if you can use that via the categories is a very individual question, depending on the content structure & requirements.

The check for $WHERE_AM_I I have rewritten as a switch, because I like to use this variable for individual template & plugin solutions and thus can use any number of "cases" without getting stuck in the if-then-else loop.
User avatar
overcat
Jr. Bludit
Posts: 4
Joined: Sat Oct 31, 2020 3:53 pm

Code: Select all

switch ($WHERE_AM_I) {
  case 'page':
    if ($page->template()) {
      include(THEME_DIR_PHP.$page->template().'.php');
    } elseif($page->categoryTemplate()){
      include(THEME_DIR_PHP.$page->categoryTemplate().'.php');
    } else {
      include(THEME_DIR_PHP.'page.php');
    }
  break;
  default:
    include(THEME_DIR_PHP.'home.php');
  break;
}
This works great!

One can also do this to add js or special code to only one page with a slug:

Code: Select all

switch ($WHERE_AM_I) {
	case 'page':
		if ($page->template()) {
			include(THEME_DIR_PHP.$page->template().'.php');
			} 
		elseif($page->categoryTemplate()){
			include(THEME_DIR_PHP.$page->categoryTemplate().'.php');
			} 
		else {
			if ($page->slug() == 'something') {include(THEME_DIR_PHP.'/singleextra/something.php');}
			else{include(THEME_DIR_PHP.'page.php');}
			}
			break;
			default:
				include(THEME_DIR_PHP.'home.php');
			break;
}
i do stuff. #women on slackware.
Post Reply