Pages

A contitional statement inside the page template? - Pages

A contitional statement inside the page template?

by oleg.bash » Tue Apr 07, 2020 7:37 pm

Is it possible to use a contitional statement inside the template?

For example, "if page_name is 'A', then include 'A.html', elseif page_name is 'B' include 'B.html' and so on?

Or even better/simpler, since we're numbering the pages, "if page_id = '1' use include '1.html'"?

Sorry for a layman's description, I'm not a coder, but I'm a rather advanced user and can customize code if I have a working prototype. This code would help me to avoid too many individual templates, sparing the database, speeding up the page load (bypassing the DB), and speeding up my work process.

I have dozens of static HTML pages that I need to integrate into the phpBB framework. If I had the above code, I could just rename those pages uniformly (A,B,C etc.) delete their current headers/footers, place them into a special /my_style/template/my_pages/ folder, and use this conditional statement to include them into the page instead of the {{ PAGE_CONTENT }}. I realize I'd still have to "create" those pages in ACP, but then I won't need to paste anything into them.

I'll still use the ACP editor for some other pages, but at least not for this set.

I would be happy if the code is a simple series of "if" lines for each individual page. Or it can be just one line of code, where page_id (1,2,3 etc.) would be equal to the include name (1.html,2.html etc.).

"Pages" is a great extension that solves many of my problems and allows great flexibility. If I also had that conditional code, I'd be all set. I'm sure it can also be useful to many other users.

Thank you for your help.
oleg.bash
Registered User
Posts: 14
Joined: Sat Sep 14, 2019 2:56 am
Contact:

Re: A contitional statement inside the page template?

by oleg.bash » Tue Apr 07, 2020 8:34 pm

It's funny, but by the time I finished writing this question, I figured it out myself! :lol:

Code: Select all

	<!-- IF PAGE_TITLE == "Example1" --> 
		{% include 'my_pages/Example1.html' %}
	<!-- ELSEIF PAGE_TITLE == "Example2" -->
		{% include 'my_pages/Example2.html' %}
	<!-- ELSEIF PAGE_TITLE == "Example3" -->
		{% include 'my_pages/Example3.html' %}
	<!-- ENDIF -->
Miraculously, it worked! So if this code is something you can use, you're welcome.
Last edited by oleg.bash on Wed Apr 08, 2020 2:22 pm
oleg.bash
Registered User
Posts: 14
Joined: Sat Sep 14, 2019 2:56 am
Contact:

Re: A contitional statement inside the page template?

by oleg.bash » Wed Apr 08, 2020 12:13 am

On the other hand, my titles are descriptive and include characters not allowed in the URL. I'd rather classify them not by titles but by given page order or by their route.

But I don't know the correct language for that. Can anyone help?

What's the equivalent of PAGE_TITLE for the page number or for the route in this context?
oleg.bash
Registered User
Posts: 14
Joined: Sat Sep 14, 2019 2:56 am
Contact: