Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[Answered] if_plugin conditionnal wrapping
I would expect this to work but if I disable aks_cache
, nothing is displayed on the site.
It is the same for other plugins, it is just an exemple…
<txp:if_plugin name="aks_cache">
<txp:aks_cache id="site-header">
</txp:if_plugin>
<header class="site-header">
[…]
</header>
<txp:if_plugin name="aks_cache">
</txp:aks_cache>
</txp:if_plugin>
Edit: Found this topic. I hoped it could work without the help of etc_query
.
Last edited by NicolasGraph (2015-06-24 10:37:49)
Offline
Re: [Answered] if_plugin conditionnal wrapping
That’s how txp sees it:
<txp:if_plugin name="aks_cache">
<txp:aks_cache id="site-header">
</txp:aks_cache>
<header class="site-header">
[…]
</header>
<txp:if_plugin name="aks_cache">
</txp:if_plugin>
</txp:if_plugin>
Offline
Offline
Re: [Answered] if_plugin conditionnal wrapping
If you don’t want to duplicate the (presumably large) <header class="site-header">[…]</header>
block, there is a hack:
<txp:php>
global $variable;
$variable['site-header'] = '<header class="site-header">[…]</header>'; // mind the quotes inside the block
</txp:php>
<txp:if_plugin name="aks_cache">
<txp:aks_cache id="site-header">
<txp:php>echo parse(parse('<txp:variable name="site-header" />'));</txp:php>
</txp:aks_cache>
<txp:else />
<txp:php>echo parse(parse('<txp:variable name="site-header" />'));</txp:php>
</txp:if_plugin>
Offline
Re: [Answered] if_plugin conditionnal wrapping
etc wrote #292035:
If you don’t want to duplicate the (presumably large)
<header class="site-header">[…]</header>
block, there is a hack:
Here are the ‘glasses’ Txp needs, thanks!
I duplicated my code first but your hack is short and it is simple as well (I mean, I can understand it…), so… Nice! I’ll use it.
Any chance Txp wouldn’t need ‘glasses’ anymore in the future?
Offline
Re: [Answered] if_plugin conditionnal wrapping
etc wrote #292035:
there is a hack
Can’t the variable assignment be done in a <txp:variable>
container?
<txp:variable name="site-header">
<header class="site-header">[…]</header>
</txp:variable>
Or have I missed some subtlety here that requires PHP?
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Offline
Offline
Offline
Offline
Re: [Answered] if_plugin conditionnal wrapping
NicolasGraph wrote #292043:
It can… Definitely. :-/
Yes, it can, but this would rend aks_cache
absolutely useless here. The purpose of aks_cache
is to store and output parsed chunks, avoiding (long, heavy…) parsing them each time. But <txp:variable />
always parses its value, even if it does not output it, so you would win nothing.
If <txp:variable />
had parse
attribute, things could look this way:
<txp:variable name="site-header" parse="0">
...
</txp:variable>
<txp:if_plugin name="aks_cache">
<txp:aks_cache id="site-header">
<txp:variable name="header" parse="1" />
</txp:aks_cache>
<txp:else />
<txp:variable name="header" parse="1" />
</txp:if_plugin>
Last edited by etc (2015-06-26 08:46:38)
Offline
Re: [Answered] if_plugin conditionnal wrapping
etc wrote #292048:
Yes, it can, but this would rend
aks_cache
absolutely useless here. The purpose ofaks_cache
is to store and output parsed chunks, avoiding (long, heavy…) parsing them each time. But<txp:variable />
always parses its value, even if it does not output it, so you would win nothing.
Oh, ok I understand. It makes sense for me now. Thanks… and let’s hack.
Last edited by NicolasGraph (2015-06-25 09:45:11)
Offline