Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2006-10-24 18:45:23
- dingoboy
- Member
- Registered: 2006-09-07
- Posts: 48
Ability to escape from PHP to HTML?
It is a big hope of mine that I will one day be able to escape from PHP code within <txp:php> ... </txp:php>
to HTML, now that the use of regular starting/closing tags (<?php
and ?>
) have been deprecated in version 4.0.4.
In my oppinion, it is not a sattisfying solution, having to make every piece of PHP code a valid block of code by itself, as stated in the FAQ about PHP use.
Is there any hope of such an improvement? :-)
Last edited by dingoboy (2006-10-24 21:27:53)
Offline
Re: Ability to escape from PHP to HTML?
In the Textpattern context, it’s hideously ugly and hackish and goes against how the the whole textpattern-tag sytem is intended to work. There’s proper ways for dealing with such needs, like writing a quick plugin, or using output_form. And for other cases there is stil heredocs:
http://us3.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
<txp:php>
if ($_SERVER['REQUEST_URI'] == '/section/666/oh-god-help-me') {
echo <<<MYHEREDOCMARKER
<h3>Special stuff</h3>
<txp:article_custom section="foo" sortby="title" sortdir="asc" category="bar" form="lofi" limit="50" listform="resume" />
MYHEREDOCMARKER;
}
</txp:php>
Having said that, everthing inside <txp:php> … </txp:php> is evaluated as regular php-code, and that includes shorttags like ?>
and <?
(and the long versions as well). So inside the code-block nobody can stop you from switching back and forth between html and code with those – I wouldn’t recommend it though, as it it’s too easy to shoot yourself in the foot. So forget I mentioned this. ;)
Offline
Re: Ability to escape from PHP to HTML?
For completion, here is the clean way to quickly add tag via a plugin:
http://svn.textpattern.com/development/4.0-plugin-template/zem_plugin_example.php
function asy_if_uri($atts, $thing) {
extract(lAtts(array(
'uri' => '',
),$atts));
return parse(EvalElse($thing, ($uri == $_SERVER['REQUEST_URI'])));
}
And your template would look as clean as ever:
<txp:asy_if_uri uri="/section/666/oh-god-help-me">
<h3>Special stuff</h3>
<txp:article_custom section="foo" sortby="title" sortdir="asc" category="bar" form="lofi" limit="50" listform="resume" />
</txp:asy_if_uri>
And if you wanted you could even add a <txp:else />
inside the conditional in the template.
Last edited by Sencer (2006-10-24 19:43:03)
Offline
#4 2006-10-24 21:30:34
- dingoboy
- Member
- Registered: 2006-09-07
- Posts: 48
Re: Ability to escape from PHP to HTML?
Sencer: Awesome. Thanks!
Offline