Textpattern Forum

You are not logged in. Register | Login | Help

#371 2011-03-07 06:46:52

mericson
Member
Registered: 2004-05-24
Posts: 121
Website

Re: smd_if: Generic multiple if condition tests

Yes, that appears to work! And, you taught a man to fish. I realized for my specific ‘localhosting’ need, the server IP address is probably easier, so changing your example to:

<txp:smd_if field="svrvar:SERVER_ADDR" operator="eq" value="127.0.0.1">
   <p>Yes, it is localhost</p>
<txp:else />
   <p>Nope, not localhost</p>
</txp:smd_if>

Thanks!

Offline

#372 2011-03-23 17:13:20

johnstephens
Plugin Author
From: Harrisonburg, VA
Registered: 2008-06-01
Posts: 820
Website

Re: smd_if: Generic multiple if condition tests

Howdy!

Quick report. This works fine for me:

<txp:smd_if field="txpvar:parent_topic" operator="in" value="x/y/z">

But 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.

For now, I don’t absolutely need the commas, so I’m keeping the default, I just though comma-separated values would be more consistent with the way the rest of Textpattern works.

Offline

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,811
Website

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.

Txp Builders – finely-crafted code, design and Txp

Offline

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

johnstephens
Plugin Author
From: Harrisonburg, VA
Registered: 2008-06-01
Posts: 820
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: 35

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: Harrisonburg, VA
Registered: 2008-06-01
Posts: 820
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: 35

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: 5,811
Website

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.

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

Board footer

Powered by FluxBB