Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#373 2011-03-23 21:04:02

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

Re: smd_if: Generic multiple if condition tests

johnstephens wrote:

if I set the list delimiter to a comma by declaring list_delim="," and use a comma to separate the values, it doesn’t work any more.

Ah, yes, a subtle annoyance. Because the plugin is already splitting the value by param_delim it gets there first and by the time it comes to splitting by list_delim there’s no commas left to operate on. You need the extra delim so you can check multiple values against multiple in-lists, e.g. value="1/2/3, 4/5/6"

Short answer: set param_delim to something other than a comma and your smd_if will parse correctly.


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

#374 2011-03-24 05:02:21

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: smd_if: Generic multiple if condition tests

Ahhh! Okay, thanks!

Offline

#375 2011-04-10 01:08:34

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

Re: smd_if: Generic multiple if condition tests

Hey Gang

I have a slight problem here
This code works:

<!-- Grabs News about the Author -->
<txp:variable name="the_author"><txp:custom_field name="author_1" /></txp:variable>
<txp:article_custom wraptag="dl" section="News" limit="500" >
<txp:smd_if field="body" operator="contains"   value='<txp:variable name="the_author" />' >
      <p><txp:posted format="%B %Y" /> : <txp:permlink><txp:title/></txp:permlink></p>
</txp:smd_if>
   </txp:article_custom>

(It searches for Body field of the News section for any instances of my book author’s name which sits in custom field “author_1”)
Proof here: http://www.talonbooks.com/authors/stephen-collis

So now I want to do the same for book titles

<!-- Grabs News about the Book -->
<txp:variable name="the_title"><txp:title /></txp:variable>
<txp:article_custom wraptag="dl" section="News" limit="500" >
<txp:smd_if field="body" operator="contains" value='<txp:variable name="the_title" />' >
      <p><txp:posted format="%B %Y" /> : <txp:permlink><txp:title/></txp:permlink></p>
</txp:smd_if>
   </txp:article_custom>

This <!— Grabs News about the Book —> code works ONLY for ONE word titles. “foo” works but not “foo foo” but in the above <!— Grabs News about the Author —> example it works for “foo” and “foo foo” and even “foo foo foo”.

can anyone explain the different results?
Is txp:title different from a txp:custom_field in some fundamental way that would cause this?

I am (as always) a little stumped.
The same result may be able to be reached by smd_each but since I haven’t used it before I am unsure.

Any help would be appreciated.
regards
Les

Last edited by lazlo (2011-04-10 01:44:12)

Offline

#376 2011-04-10 02:16:33

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: smd_if: Generic multiple if condition tests

I don’t know if this will help, but I notice that the title tag does not give you the raw output, even when you set the no_widow flag to 0.

Maybe you can use this instead?

<txp:php>echo $thisarticle['title'];</txp:php>

Offline

#377 2011-04-10 03:20:25

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

Re: smd_if: Generic multiple if condition tests

Sweet that works… :0 almost wonderfully.

Of course nothing is perfect so I need help with this:

In book titles with apostrophes like “Bash’d” or “foo’d” I get this syntax error:

Parse error: syntax error, unexpected T_STRING in /Applications/MAMP/htdocs/talon/textpattern/lib/txplib_misc.php(638) : eval()’d code(296) : eval()’d code on line 1
Tag error: <txp:smd_if field=“body” operator=“contains” value=’<txp:variable name=“the_title” />’ > -> Notice: Array to string conversion on line 307
textpattern/lib/txplib_misc.php(638) : eval()’d code:307 join()
textpattern/publish.php:1169 smd_if()
textpattern/publish.php:1104 processTags()
textpattern/publish.php:838 parse()
textpattern/publish.php:955 doArticles()
textpattern/publish.php:945 parseArticles()
textpattern/publish.php:1169 article_custom()
textpattern/publish.php:1104 processTags()
textpattern/publish/taghandlers.php:3219 parse()
textpattern/publish.php:1169 if_individual_article()

My new code:

<txp:if_individual_article>
<txp:variable name=“the_title”><txp:php>echo $thisarticle[‘title’];</txp:php></txp:variable>
<txp:article_custom wraptag=“dl” section=“News” limit=“500” >
<txp:smd_if field=“body” operator=“contains” value=’<txp:variable name=“the_title” />’ > <p><txp:posted format=”%B %Y” /> : <txp:permlink><txp:title/></txp:permlink></p>
</txp:smd_if> </txp:article_custom>
</txp:if_individual_article>

Any advice on escaping the apostrophes in the php call or is this more of a bug in the smd_if code?
Or scolding saying I used it wrong.

regards
Les

Last edited by lazlo (2011-04-10 03:44:27)

Offline

#378 2011-10-07 16:14:43

pafruu
Member
From: New Brunswick, Canada
Registered: 2010-01-14
Posts: 65

Re: smd_if: Generic multiple if condition tests

Hey guys,

I’m using smd_if for the first time, I can’t believe I never used it before.

What I am trying to achieve is this:

I am currently working on an RV vehicule website where I have a listing of vehicules. What I would like the users to be able to do is this. They could sort the articles by the KM of the vehicule, the asking price, the year or the make of the vehicule.

I am using a <form> because I want the user to be able to see what are the different values they can choose from.
Here is what I have in code (I know it is incomplete):

<form name="viewlist" ACTION="" METHOD="POST" ><div style="position:relative;top:10px;">Sort by: <select name="rank" id="ranks">
<option value="new" selected>Newest First</option>
<option value="old">Oldest First</option>
<option value="PriceHL">Price High to Low</option>
<option value="PriceLH">Price Low to High</option>
<option value="kmHL">KM High to Low</option>
<option value="kmLH">KM Low to High</option>
<option value="YearHL">Year New to Old</option>
<option value="YearLH">Year Old to New</option>
<option value="make">Make</option>
</select><div style="float:right;position:relative;top:0px;"><span style="padding-right:20px;"><input type="radio" name="view" value="list" checked="checked" onclick="DisplayMeasure();" />List View</span><span style="padding-right:10px;"><input type="radio" name="view" value="photo" onclick="DisplayMeasure();" />Photo View</span></div></div>
<div class="clear"></div></form>

here is the form that should display the content:

<div id="listGood" style="display:block" >
<txp:smd_if field="txpvar:tri" operator="eq" value="new">
  <txp:article_custom allowoverride="1" excerpted="1" form="list" limit="999" pgonly="0" section="inventory" sort="Posted desc" status="4" />
</txp:smd_if>
<txp:smd_if field="txpvar:tri" operator="eq" value="old">
  <txp:article_custom allowoverride="1" excerpted="1" form="list" limit="999" pgonly="0" section="inventory" sort="Posted asc" status="4" />
</txp:smd_if>
<txp:smd_if field="txpvar:tri" operator="eq" value="PriceHL">
  <txp:article_custom allowoverride="1" excerpted="1" form="list" limit="999" pgonly="0" section="inventory" sort="Posted desc" status="4" />
</txp:smd_if>
</div>
<div id="pictGood" style="display:none" >
<txp:article_custom form="ph" section="inventory" status="4" />
</div>

now I am trying to figure out a way to declare the txp:variable for the multiple values in the id=“rank”. I stubbled upon a plugin called: adi_gps but I can’t seem to make it work.

Should I post it as:

<txp:adi_gps name="tri" />

If so where? Please help


I try, and I try, and I try…. and sometimes I achieve

Offline

#379 2011-10-07 16:47:31

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

Re: smd_if: Generic multiple if condition tests

pafruu wrote:

What I am trying to achieve is <snip>

If all you’re trying to do is figure out which of the values in the ‘rank’ are set then you may not need smd_if. Proceed as follows:

  1. Keep your HTML form as you have it now
  2. At the top of the destination page add <txp:adi_gps post="1" /> (since you’re using method=“post”)
  3. That will automagically create you a <txp:variable> named “rank”
  4. Use a series of <txp:if_variable> tags to check its contents and take appropriate action

Another approach for step 4 might be to simply use smd_if to verify that the returned result is “in” a valid list of sort orders and if it is (i.e. in the smd_if container) plug the value into the sort="" value in the <txp:article_custom> tag. Check out smd_if’s {replacement} variable examples for how to do this. That way you only have one thing to check and one article_custom tag to maintain.

See how you get on with that.

Last edited by Bloke (2011-10-07 16:48:58)


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

#380 2011-10-07 17:25:33

pafruu
Member
From: New Brunswick, Canada
Registered: 2010-01-14
Posts: 65

Re: smd_if: Generic multiple if condition tests

Thks Bloke fr your prompt reply :)

I tried what you’ve suggested but it is not working.
Although, I do not have a destination page, the form and the results are on the same page see here:

http://www.girvanmediahost.com/bouctoucheRV.com/inventory

Does this affect anything??

when the <txp:adi_gps post=“1” /> I had no results at all
but when i typed in <txp:variable name=“rank” value=“new” />
i had one listing show up

EDIT:

thanks for your help, I managed to make it work with good old javascript. Not pretty, but it works hehe!!

Last edited by pafruu (2011-10-07 19:20:47)


I try, and I try, and I try…. and sometimes I achieve

Offline

#381 2011-10-07 22:05:57

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

Re: smd_if: Generic multiple if condition tests

pafruu wrote:

I do not have a destination page, the form and the results are on the same page see here:

Doesn’t make any difference — in that case you just have to put <txp:adi_gps/> on the same page and then use <txp:if_variable> or <txp:smd_if> to detect if the rank variable’s been set with something.

when the <txp:adi_gps post=“1” /> I had no results at all

Hmmm, so let me get this straight in my head: you wrote an HTML form with a select list. The select list has name="rank" and the form has method="post" (lower case? Does it matter these days). Somewhere near the very top of the page flow you put a call to <txp:adi_gps post="1" /> and then somewhere further down the page you used <txp:variable name="rank" /> to display the value you submitted from the form’s submit button or onsubmit() method, and you saw no value displayed?

Without seeing any code, all I can say is that it should work. Can’t think of anything you missed. A puzzler.

I managed to make it work with good old javascript. Not pretty, but it works hehe!!

That would have been my other suggested approach. There are a few jQuery table sort plugins that allow you to click table headings and reorder data on the fly client-side. If you’re not paging results those are pretty handy.


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

#382 2012-01-28 01:01:10

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

Re: smd_if: Generic multiple if condition tests

v0.91 fixes some long-standing issues and adds a few new things as well:

  • Fixed pretext check for section/category (thanks saccade). Note that you must now use s if you want to test the current (URL-based) section
  • Added explicit checks for pretext, file, link, image, and article. These are handy if you don’t want to trust the inbuilt hierarchy, so you could specify field="image:name" to be absolutely clear on the name to which you were referring
  • Added var_prefix to allow nesting of smd_if tags without replacement clashes
  • Added :COUNT operator modifier (thanks the_ghost)
  • Added :ESC and :ESCALL modifiers
  • Finally fixed checks for defined / undefined so they’re actually useful

Hopefully this version allows you to do more stuff in a conditional funk. Enjoy.


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

#383 2012-03-01 01:27:10

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Re: smd_if: Generic multiple if condition tests

I try to filter articles using smd_if and smd_query.
I check the url to see if some urlvar are used then build a query to select specific articles.
If I view URL like this everything goes fine:

http://www.garfagnanabikers.it/itinerari/?foo=foo

but, how can I tell smd_if to execute normal (i.e. view all articles ) code when nothing urlvar are used?

Offline

#384 2012-03-01 01:40:54

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

Re: smd_if: Generic multiple if condition tests

wornout wrote:

http://www.garfagnanabikers.it/itinerari/?foo=foo

Does:

<txp:smd_if field="urlvar:foo" operator="undefined">
   // View all articles here
<txp:else />
   // View subset of articles based on value of foo here
</txp:smd_if>

work? Or you could switch the logic and use operator="defined". v0.91 should be able to do that kind of thing no problem.

Last edited by Bloke (2012-03-01 01:41:42)


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

Board footer

Powered by FluxBB