Page 3 of 3

Re: Custom template for the pages

Posted: Fri Jul 16, 2021 10:27 pm
by Edi
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?

Re: Custom template for the pages

Posted: Mon Jul 19, 2021 12:14 pm
by novafacile
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.

Re: Custom template for the pages

Posted: Mon Aug 09, 2021 12:20 pm
by overcat

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;
}