Custom template for the pages

User avatar
Torsten_Kelsch
Legend Bludit
Posts: 236
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Contact:

Torsten_Kelsch wrote: Tue May 28, 2019 9:07 pm Nice workaround, but it would be better if editors could choose the template in the backend …
This is implemented in 3.9.2 (and perhaps in a few earlier minor versions).
On Error GoTo Bed
Carstenap
Jr. Bludit
Posts: 4
Joined: Fri Dec 27, 2019 5:38 pm

Torsten_Kelsch wrote: Mon Sep 16, 2019 11:32 pm
Torsten_Kelsch wrote: Tue May 28, 2019 9:07 pm Nice workaround, but it would be better if editors could choose the template in the backend …
This is implemented in 3.9.2 (and perhaps in a few earlier minor versions).
@torsten, could you please explain how to achieve this?

In backend under "options" i see the field for "template" but how do I choose my own new template so that it works?

I made a new file called "newpage.php" and put it in the folder PHP, but how do I actually get it to select this new php file template?

/Carsten - New member
User avatar
Torsten_Kelsch
Legend Bludit
Posts: 236
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Contact:

Manage > Content > Edit > Options > Advanced > Template
Verwalten > Inhalte > Bearbeiten > Einstellungen > Erweitert > Template
Attachments
bludit-template.png
bludit-template.png (25.95 KiB) Viewed 1588 times
On Error GoTo Bed
puschmie
Jr. Bludit
Posts: 7
Joined: Thu Oct 29, 2020 12:12 pm
Location: Vienna
Contact:

Torsten_Kelsch wrote: Wed Jan 01, 2020 12:26 am Manage > Content > Edit > Options > Advanced > Template
Verwalten > Inhalte > Bearbeiten > Einstellungen > Erweitert > Template
Could you maybe explain a little bit more? Is the template a template for a page? What should a template file look like? Should I save it in the php folder?
Thanks :)
User avatar
Torsten_Kelsch
Legend Bludit
Posts: 236
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Contact:

@puschmie: Yes, it is a template file for pages, and it should look similar to those in your theme folder (/bl-themes/[theme-name]/php), and you can name it as you wish, let’s say special-page.php or whatever. Also see https://docs.bludit.com/en/themes/theme-basics.
On Error GoTo Bed
User avatar
overcat
Jr. Bludit
Posts: 3
Joined: Sat Oct 31, 2020 3:53 pm

Hi and hello from Vienna. After trying various flat file CMS's, i've finally found BLUDIT and it is all i have been looking for. Thanks a lot for this!

I am now having issue with this new page template function - newest version fresh install.
So if i understand correctly, i shall

1 - create a template php file in my /bl-mytheme/php/ folder as
/bl-mytheme/php/my-static-page.php
with some content, or for starters i will just copy the page.php code with some markers to be able to distinguish it from the original :mrgreen:

2 - in backend, at page edit, i will enter the "my-static-page.php" in ->options -> template

Here, i've tried both
my-static-page.php
and
my-static-page

but neither seems to work. Am i omitting something?
I've checked the bl-content/databases/page.php and the template is being correctly written to the file, but obviously not used.
Thanks!
Danke und Grüße
Last edited by overcat on Sat Oct 31, 2020 4:08 pm, edited 2 times in total.
i do stuff. #women on slackware.
User avatar
Edi
Site Admin
Posts: 2332
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

overcat wrote: Sat Oct 31, 2020 4:00 pm 2 - in backend, at page edit, i will enter the "my-static-page.php" in ->options -> template
This function does not work yet work.

The template is defined in the file index.php of the theme:

Code: Select all

<?php
   // $WHERE_AM_I variable detect where the user is browsing
   // If the user is watching a particular page/post the variable takes the value "page"
   // If the user is watching the frontpage the variable takes the value "home"
   if ($WHERE_AM_I == 'page') {
      include(THEME_DIR_PHP.'page.php');
   } else {
      include(THEME_DIR_PHP.'home.php');
   }
?>
Here you can add more conditions. For example:

Code: Select all

<?php
   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).
User avatar
Torsten_Kelsch
Legend Bludit
Posts: 236
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Contact:

Edi wrote: Sat Oct 31, 2020 11:19 pm
overcat wrote: Sat Oct 31, 2020 4:00 pm 2 - in backend, at page edit, i will enter the "my-static-page.php" in ->options -> template
This function does not work yet
It does not work yet? I did not know that, because I have not tried it already, but I’m wondering why this option isn’t greyed out then.
On Error GoTo Bed
User avatar
overcat
Jr. Bludit
Posts: 3
Joined: Sat Oct 31, 2020 3:53 pm

Hi, thanks. That is one of the things which makes me like bludit - pure PHP and very logical. :)
Too bad, that there is a function which "undocumented does not work yet" - but thanks for clearing this out for me.

8-) The index.php way works fine and it would be enough ;)
(no bloated UI - the text version in index.php is manageable better anyway)
i do stuff. #women on slackware.
Post Reply