Custom template for the pages

User avatar
Torsten_Kelsch
Legend Bludit
Posts: 263
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Has thanked: 4 times
Been thanked: 2 times
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: 263
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Has thanked: 4 times
Been thanked: 2 times
Contact:

Manage > Content > Edit > Options > Advanced > Template
Verwalten > Inhalte > Bearbeiten > Einstellungen > Erweitert > Template
Attachments
bludit-template.png
bludit-template.png (25.95 KiB) Viewed 4603 times
On Error GoTo Bed
puschmie
Ssr. Bludit
Posts: 10
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: 263
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Has thanked: 4 times
Been thanked: 2 times
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: 4
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: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
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');
}
?>
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
Torsten_Kelsch
Legend Bludit
Posts: 263
Joined: Thu Aug 27, 2015 10:24 pm
Location: Germany
Has thanked: 4 times
Been thanked: 2 times
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: 4
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.
bnetz
Ssr. Bludit
Posts: 18
Joined: Sun Aug 16, 2020 6:38 pm

This function does not work yet work.
Now it's some months later - is it planned that this function is coming to life maybe in Bludit 4.x?
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 …)
Post Reply