Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-06-23 11:36:50

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

[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)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#2 2015-06-23 12:25:00

etc
Developer
Registered: 2010-11-11
Posts: 5,054
Website GitHub

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

#3 2015-06-23 12:33:18

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: [Answered] if_plugin conditionnal wrapping

etc wrote #291869:

That’s how txp sees it:

Ok, I need the txp:glasses plugin! :)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#4 2015-06-25 08:56:13

etc
Developer
Registered: 2010-11-11
Posts: 5,054
Website GitHub

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

#5 2015-06-25 09:04:39

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

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?


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#6 2015-06-25 09:11:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

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

#7 2015-06-25 09:17:56

etc
Developer
Registered: 2010-11-11
Posts: 5,054
Website GitHub

Re: [Answered] if_plugin conditionnal wrapping

Bloke wrote #292040:

Or have I missed some subtlety here that requires PHP?

The subtlety is to avoid parsing <header class="site-header">[…]</header> block if aks_cache is available. If stored as you suggest, it will always be parsed.

Offline

#8 2015-06-25 09:18:17

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: [Answered] if_plugin conditionnal wrapping

Bloke wrote #292040:

Can’t the variable assignment be done in a <txp:variable> container?

It can… Definitely. :-/


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#9 2015-06-25 09:19:31

etc
Developer
Registered: 2010-11-11
Posts: 5,054
Website GitHub

Re: [Answered] if_plugin conditionnal wrapping

NicolasGraph wrote #292039:

Any chance Txp wouldn’t need ‘glasses’ anymore in the future?

Where will the fun be, then?

Offline

#10 2015-06-25 09:24:36

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: [Answered] if_plugin conditionnal wrapping

etc wrote #292044:

Where will the fun be, then?

Alright; let’s have fun… ;)

Last edited by NicolasGraph (2015-06-25 09:24:59)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#11 2015-06-25 09:34:38

etc
Developer
Registered: 2010-11-11
Posts: 5,054
Website GitHub

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

#12 2015-06-25 09:44:44

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: [Answered] if_plugin conditionnal wrapping

etc wrote #292048:

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.

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)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

Board footer

Powered by FluxBB