Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2014-10-07 13:32:04

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

Re: chh_if_data revisited

gomedia wrote #284577:

I’ve tried another solution which, this time, only performs one parse. It’s available here.

Almost there! I just would like to be able to parse the content of adi_if_content_insert only if the “important” content is not empty. You could add another tag, say, adi_if_content_ignore that will always be parsed, but not considered as “important”.

I have actually written another version, that additionally supports test, ignore and insert attributes.

Whatever works, adi_if_content is a clear “Plugin of the Year” winner for me atm!

Offline

#14 2014-10-08 00:37:47

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: chh_if_data revisited

etc wrote #284586:

Almost there! I just would like to be able to parse the content of adi_if_content_insert only if the “important” content is not empty. You could add another tag, say, adi_if_content_ignore that will always be parsed, but not considered as “important”.

Would “parse only if important content not empty” mode be better as the default for adi_if_content_insert? So all inserted content is parsed only if necessary? If I’ve misunderstood have you got an example?

I have actually written another version, that additionally supports test, ignore and insert attributes.

Yikes, someone who knows what they’re doing! It puts my if-then-else coding style to shame.

Whatever works, adi_if_content is a clear “Plugin of the Year” winner for me atm!

Not sure about that, but it’s doing the job for me very nicely in a couple of projects at the moment.

Offline

#15 2014-10-08 07:56:20

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

Re: chh_if_data revisited

There is nothing wrong with if-then-else, but having ignore attribute is handy. You can set it by default to site_name,site_url,... and not care about these anymore.

gomedia wrote #284593:

Would “parse only if important content not empty” mode be better as the default for adi_if_content_insert? So all inserted content is parsed only if necessary? If I’ve misunderstood have you got an example?

Sometimes you want it be parsed before (adi_if_content_ignore), sometimes after (adi_if_content_insert) the test content is checked for non-emptiness.

Offline

#16 2014-10-09 07:06:01

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

Re: chh_if_data revisited

A clever marginal usecase of processing insert after test:

<txp:adi_if_content insert="newer,older">
	<txp:newer>Newer</txp:newer>
	<txp:older>Older</txp:older>
	<txp:article />
</txp:adi_if_content>

Bye-bye pgonly!

Offline

#17 2014-10-10 15:31:22

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: chh_if_data revisited

All progress sounds good, but I’m confused about the current state of tgas, attributes and their abilities.

Offline

#18 2014-10-10 22:06:12

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: chh_if_data revisited

mrdale wrote #284708:

All progress sounds good, but I’m confused about the current state of tgas, attributes and their abilities.

Yeah, I know what you mean. I haven’t had a chance to test etc’s solution yet. However this turns out, code readability (& understandability?) is essential as far as I’m concerned.

Offline

#19 2014-10-11 09:09:01

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

Re: chh_if_data revisited

mrdale wrote #284708:

All progress sounds good, but I’m confused about the current state of tgas, attributes and their abilities.

One should speak of current states, since we have two plugin versions atm. Mine works like this:

<txp:adi_if_content [ test="tag1,tag2" | ignore="tag3,tag4" ] [ insert="tag5,tag6" ]>
	...
	<!-- will be processed, but not tested for emptiness -->
	<txp:adi_if_content_ignore><txp:tag7 /></txp:adi_if_content_ignore>
	<txp:tag8 />
	...
	<txp:tag1 /> <!-- will be processed and tested for emptiness -->
	...
	<!-- will be processed after other tags only if the "tested" tags are not all empty -->
	<txp:adi_if_content_insert><txp:tag9 /></txp:adi_if_content_insert>
	<txp:tag6 />
	...
</txp:adi_if_content>

test and ignore are mutually exclusive, choose the one you prefer. If both omitted, all tags except in insert will be tested. ignore and insert act exactly as if tags were wrapped in adi_if_content_ignore and adi_if_content_insert.

Example (try it also without wrapping in adi_if_content):

<txp:adi_if_content insert="newer,older">
	<!-- these will be processed after <txp:article />, so the pagination data will be available -->
	<txp:newer>Newer</txp:newer><txp:older>Older</txp:older>
	<!-- this one will be processed normally and populate the pagination data -->
	<txp:article />
</txp:adi_if_content>

Last edited by etc (2014-10-11 09:19:41)

Offline

#20 2014-10-11 21:26:10

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: chh_if_data revisited

Hi etc,

Your solution looks pretty groovy to me. I’ve dropped it into a couple of projects and all seems well. It’s a better job than my attempt, so I reckon you should release it as etc_if_content.

Adi

Offline

#21 2014-10-12 09:44:16

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

Re: chh_if_data revisited

Ha! you know how some people are, they would say etc_plugin = adi_idea + rvm_code. What the name would change, anyway? Adopt whatever approach you prefer in your plugin, I only wanted to share mine, period.

A bit OT, but I’m more and more persuaded that Ruud’s (?) great parser is underexploited. Your plugin was an occasion to tweak it. Now I’m playing with caching the parsing, it gives a 2-3 times acceleration.

Offline

#22 2014-10-12 22:40:52

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: chh_if_data revisited

etc wrote #284738:

What the name would change, anyway?

etc_support?

Offline

#23 2014-10-13 07:30:10

jpdupont
Member
Registered: 2004-10-01
Posts: 752

Re: chh_if_data revisited

Adi, etc,

Is it allowed to insert before/after the tags tested ?

Offline

#24 2014-10-13 07:45:36

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

Re: chh_if_data revisited

gomedia wrote #284741:

etc_support?

wouldn’t be any different, whatever prefix, because I like this plugin. Let’s finish with etymology, or there will be no users to support. :)

jpdupont wrote #284752:

Is it allowed to insert before/after the tags tested ?

Yes, and one day it could even be possible to assign some finer processing order to tags.

Offline

Board footer

Powered by FluxBB