Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-12-06 11:58:08

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 205
Website

error_default form does not understand <txp:> when using php-includes

I had this problems for years and never could figure out what to do about it.
My pages in textpattern usually look like that:

<txp:php>
include 'header.php';
include 'default.php';
include 'footer.php';
</txp:php>

Whereas I change “default” whenever I need to.
I do this to be able to conveniently edit those files directly in my editor.
So I thought for error_default or error_404 this should work (but it doesn´t):

<txp:php>
include 'header.php';
include 'error.php';
include 'footer.php';
</txp:php>

In that case the form does not seem to understand the txp tags inside the included files. Is there any clever way around that?
I would like to display my header (menu, logo etc) on the error page. So I want to define it by one and the same file (header.php).

Offline

#2 2021-12-06 12:29:56

etc
Developer
Registered: 2010-11-11
Posts: 4,665
Website GitHub

Re: error_default form does not understand <txp:> when using php-includes

Hi Christian,

there is a difference between parsing the ‘normal’ pages and the ‘error’ pages. The former ones are (normally) parsed twice, while the latter ones are parsed only once. In you case, on the first pass the .php files are just included, but parsed only on the second one. Which means they are just output verbatim on error pages.

You can try to replace it with

<txp:php>
echo parse(
    file_get_content('header.php').
    file_get_content('error.php').
    file_get_content('footer.php');
);
</txp:php>

or something similar.

Offline

#3 2021-12-06 12:41:15

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 205
Website

Re: error_default form does not understand <txp:> when using php-includes

Thanks etc. Great stuff.

<txp:php>
echo parse(
    file_get_contents('header.php').
    file_get_contents('error.php').
    file_get_contents('footer.php')
);
</txp:php>

did the trick (contents and no ;).

Can file_get_contents be a performance issue? I think I had a problem related to a similar aproach I tried once with file_get_contents.

Last edited by demoncleaner (2021-12-06 12:41:45)

Offline

#4 2021-12-06 12:49:29

etc
Developer
Registered: 2010-11-11
Posts: 4,665
Website GitHub

Re: error_default form does not understand <txp:> when using php-includes

demoncleaner wrote #332094:

(contents and no ;).

Oops, sorry.

Can file_get_contents be a performance issue?

It could. In this case, you can try to play with the output buffer.

Offline

Board footer

Powered by FluxBB