Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#445 2016-04-14 06:04:12

lazlo
Member
Registered: 2004-02-24
Posts: 110

Re: smd_if: Generic multiple if condition tests

Hey Stef

Thanks for the wonderful plugin.

I have a problem constructing the correct call, and I am looking for guidance.

Currently my code looks like this:

<txp:variable name="direction" />

<txp:smd_if field="txpvar:direction" operator="in" value="Drama/Poetry/Fiction/Non-Fiction" logic="or">
<txp:output_form form="contributors_list" />
</txp:smd>

<txp:variable name=“direction” /> is populated through PHP from my site menu structure ?Drama ?Poetry ?Fiction ?Non-Fiction etc.

Parsing Drama, Poetry and Fiction work and they call <txp:output_form form=“contributors_list” /> but Non-Fiction does not. At first I thought it was the hyphen (dash) that was the problem so I removed it and that didn’t fix the problem.

But if I change the Non-Fiction to Non-Fict it will now call <txp:output_form form=“contributors_list” /> so it seems Non-Fiction doesn’t work because it contains “Fiction”.

I tried <txp:smd_if field=“txpvar:direction” operator=“eq, eq, eq, eq,” value=“Drama,Poetry,Fiction,Non-Fiction” logic=“or”> but it fails as well.

Preferably I would like to use “Non-Fiction” in the variable because it has downstream code that matches my category names.

Thanks in advance.

Last edited by lazlo (2016-04-14 06:04:47)

Offline

#446 2016-04-14 09:02:02

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

Re: smd_if: Generic multiple if condition tests

lazlo wrote #298607:

it seems Non-Fiction doesn’t work because it contains “Fiction”.

Very strange indeed. I tried it on my test box using a sanitised, hard-coded value of direction and it worked fine. Here’s my code. Note that I tidied up the closing smd_if tag too (but that probably doesn’t have a bearing on it) and dropped the logic attribute since the in operator implies it.

<txp:variable name="direction" value="Non-Fiction" />

<txp:smd_if field="txpvar:direction" operator="in" value="Drama/Poetry/Fiction/Non-Fiction">
Match made in heaven.
<txp:else />
No match this time :-(
</txp:smd_if>

So I wonder if there’s something else at play here. Firstly, could you go back to basics, copy the code above and see what you get out. If it works we may need to investigate how your direction variable is being populated. Perhaps it has a rogue space on the end of it or something, and it needs trimming first (though that wouldn’t explain why Non-Fict worked).

A few things you can try:

  • Add debug="2" to the smd_if tag and check the values it is comparing match what you expect.
  • Swap the order of the items in the value attribute list so Non_Fiction comes before Fiction.
  • Check you’re using the very latest plugin version (0.91) or try the beta 0.92 (which I doubt will affect anything in this instance because it only adds pref matching support).

Past that I’m not sure what could be going on. If none of the above fixes it, by all means drop me a temporary login to the site (if possible) and I’ll see if I can figure it out in situ.


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

#447 2016-04-14 21:18:12

lazlo
Member
Registered: 2004-02-24
Posts: 110

Re: smd_if: Generic multiple if condition tests

Bloke wrote #298610:

Firstly, could you go back to basics, copy the code above and see what you get out. If it works we may need to investigate how your direction variable is being populated.

Thank you very much Stef, unbeknownst to me there was a char limit exception on PHP code that populated direction. I thought I had sanitized my test before contacting you, thanks for the help in confirming that it was my problem and not a problem with smd_if.

Offline

#448 2017-03-06 03:53:21

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: smd_if: Generic multiple if condition tests

Tag error: <txp:smd_if field="excerpt" operator="isempty"> ->  Textpattern Notice: unregistered_tag while parsing form None on page sandbox
textpattern/lib/txplib_publish.php:518 trigger_error()
textpattern/lib/txplib_publish.php:463 processTags()
textpattern/publish.php:1006 parse()
textpattern/publish.php:1110 doArticles()
textpattern/publish.php:1099 parseArticles()
article_custom()
textpattern/vendors/Textpattern/Tag/Registry.php:83 call_user_func()
textpattern/lib/txplib_publish.php:514 Textpattern\Tag\Registry->process()
textpattern/lib/txplib_publish.php:463 processTags()
textpattern/lib/txplib_misc.php:4476 parse()

Testing here

Calling it as such:

<txp:smd_if field="excerpt" operator="isempty"> aaaaaa <txp:body /><txp:else /> bbbbbb
<txp:excerpt /> cccccc <txp:permlink>more</txp:permlink> 
</txp:smd_if> dddddd

Smd_if plugin seems to be working correctly on the frontend; I just want to make sure I’m doing it right/am I missing something that’s causing the error?


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#449 2017-03-06 05:19:43

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: smd_if: Generic multiple if condition tests

Okay so plugin help indicates that my usage won’t work (although it seemed to, on the frontend), however I’m not so far able to wrap my head around what the correct tag should be.. I would just like to check whether the excerpt field is empty (or not).


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#450 2017-03-06 08:38:57

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

Re: smd_if: Generic multiple if condition tests

alicson wrote #304419:

I would just like to check whether the excerpt field is empty (or not).

Doesn’t if_excerpt do the job for you? And don’t worry about any ‘unregistered tag’ warnings: they’re just warnings for now and will be for a version or two of Textpattern yet. I’ll tend to each plugin as I get a chance.


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

#451 2017-03-06 09:29:59

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: smd_if: Generic multiple if condition tests

Bloke wrote #304427:

Doesn’t if_excerpt do the job for you?

Documentation didn’t indicate that it will parse txp:else — I need it for “if_no_excerpt”. If it will parse txp:else then it will yes do the job :)


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#452 2017-03-06 09:47:36

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

Re: smd_if: Generic multiple if condition tests

alicson wrote #304434:

Documentation didn’t indicate that it will parse txp:else — I need it for “if_no_excerpt”. If it will parse txp:else then it will yes do the job :)

All conditional tags support <txp:else />.


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

#453 2017-03-06 09:54:30

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: smd_if: Generic multiple if condition tests

Yay then if_excerpt is perfect :) (Documentation seems pretty consistent about individually mentioning availability of txp:else for most conditional tags.)

Am I using smd_if correctly here or can I manage this one with built-in tags too? <txp:smd_if field="category1, category2" value="ridiculi">


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#454 2017-03-06 15:04:39

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: smd_if: Generic multiple if condition tests

alicson wrote #304443:

Am I using smd_if correctly here or can I manage this one with built-in tags too? <txp:smd_if field="category1, category2" value="">

In an article list page:

<txp:if_category name="ridiculi">
        ...
</txp:if_category>

In an article form:

<txp:if_article_category name="ridiculi">
        ...
</txp:if_article_category>

Offline

#455 2017-03-08 05:38:08

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: smd_if: Generic multiple if condition tests

michaelkpate wrote #304455

Thank you!


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#456 2017-03-16 22:35:39

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: smd_if: Generic multiple if condition tests

To replace the very handy <txp:glx_if_section_frontpage>, how may I form the <txp:smd_if> ?

If needs to be specific to a particular section/page, I was thinking I could do e.g. IF <txp:page_url /> = <txp:site_url />/pictures ..
I haven’t quite wrapped my head around urlvar, etc../which fields to use in this case to effectively form the smd_if.


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

Board footer

Powered by FluxBB