Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#205 2009-01-25 03:10:21

dl33
Member
Registered: 2006-06-17
Posts: 192
Website

Re: smd_if: Generic multiple if condition tests

Not sure if I am getting this right; how would you check for the link_url of a link? I got the following code right now:

<txp:smd_if field="link_url" operator="eq" value="#">
	<txp:link_description escape=""/>
<txp:else />
	<a href="<txp:link_url />" title="<txp:link_name />" class="sel_underline"><txp:link_description escape=""/></a>
</txp:smd_if>

I also tried:

<txp:variable name="islink" value='<txp:link_url>' />
<txp:smd_if field="txpvar:islink" operator="eq" value="#">

What would I need to change in order to get this working?

Offline

#206 2009-01-25 14:31:59

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

Re: smd_if: Generic multiple if condition tests

dl33 wrote:

how would you check for the link_url of a link?

You’re very close:

Method 1: the actual field name is “url”, not “link_url”
Method 2: needs a closing / on your txp:link_url tag

For finding out the field names, put debug="2 into the smd_if tag and you’ll see 5 sections output with the names of all the variables available to the plugin. The one you want to look at is headed “THIS LINK:”.

Last edited by Bloke (2009-01-25 14:32:38)


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

#207 2009-02-25 13:39:41

hamato
New Member
Registered: 2009-02-21
Posts: 9

Re: smd_if: Generic multiple if condition tests

I am trying to filter articles by custom field. I want to list 3 articles that have customfieldname value more then 5 (numeric).
Something like <txp:article_custom status="sticky" customfieldname=">5" />.

Since <txp:article_custom /> filter does not have a support for this range of values (>5, more than 5) I tried to accomplish this with a combination of <txp:article_custom /> and <txp:smd_if>.

The problem I’m running to is an offset. I dont want to set offset on ANY sticky article, but on a sticky article that passes <txp:smd_if> conditional test.

Also, if I dont set an offset, I still have a problem with results if I set a limit for the number of articles that will be displayed. For example, if I set a limit of 3 articles I might get no results, or maybe 1 or 2 results, depending of customfieldname value. Sometimes I will get all 3 results, but only if all 3 articles (that are being parsed first by <txp:article_custom />) pass that conditional test.

I’ve simplified my code for this example and it looks something like this:

<txp:article_custom status="sticky" limit="3" sort="custom_9 asc" offset="3">
	<txp:smd_if field="customfieldname" operator="gt:NUM" value="5">
		<h3><txp:title /></h3>
	</txp:smd_if>
</txp:article_custom>

Is there any way to do this with smd_if or maybe I should try to do something with smd_query?

Thanks in advance, and thank you Bloke for making this very useful plugin.

Offline

#208 2009-02-25 14:14:40

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_if: Generic multiple if condition tests

Off the top of my head:

Get the ids of all sticky articles, already sorted, and save them on a variable.

<txp:variable name="ids" value='<txp:article_custom status="sticky" sort="custom_9 asc"><txp:article_id /><txp:if_last_article><txp:else />,</txp:if_last_article></txp:article_custom>' />

Then, use that variable as the value for id attribute on article custom:

<txp:article_custom id='<txp:variable name="ids" />' limit="3" offset="3">
	<txp:smd_if field="customfieldname" operator="gt:NUM" value="5">
		<h3><txp:title /></h3>
	</txp:smd_if>
</txp:article_custom>

Not sure how nice will limit and offset play if the lists of ids passed to article_custom is longer than the values of those attributes.

Could you please test this idea? Thanks!


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#209 2009-02-25 15:23:15

hamato
New Member
Registered: 2009-02-21
Posts: 9

Re: smd_if: Generic multiple if condition tests

Thank you very much for this approach Maniqui, I think I’m getting close to a solution, and I think that limit and offset are working fine.

The problem I’m dealing now is a sort order of article IDs in article_custom. I can sort them in a coma separated list of IDs, but that doesn’t affect a sort order of next article_custom where that list of IDs is supplied.

As stated here: http://textbook.textpattern.net/wiki/index.php?title=article_custom

id=“article ID”
IMPORTANT: When a list is supplied, this does not imply a sort order.

When I try to add sort="custom_9 asc" to a second part of your code, sort order is good but limit and offset are not working as I want them to. Same problem appears as in my first post.

<txp:variable name="ids" value='<txp:article_custom status="sticky" sort="custom_9 asc"><txp:article_id /><txp:if_last_article><txp:else />,</txp:if_last_article></txp:article_custom>' />

<txp:article_custom id='<txp:variable name="ids" />' limit="3" offset="3" sort="custom_9 asc">
	<txp:smd_if field="customfieldname" operator="gt:NUM" value="5">
		<h3><txp:title /></h3>
	</txp:smd_if>
</txp:article_custom>

Last edited by hamato (2009-02-25 15:49:21)

Offline

#210 2009-02-25 15:47:29

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_if: Generic multiple if condition tests

Hi Hamato,

yeah, you are right, I forgot something: try this

<txp:article_custom id='<txp:variable name="ids" />' limit="3" offset="3" sort='FIELD(ID,<txp:variable name="ids" />)'>
	<txp:smd_if field="customfieldname" operator="gt:NUM" value="5">
		<h3><txp:title /></h3>
	</txp:smd_if>
</txp:article_custom>

I have added sort='FIELD(ID,<txp:variable name="ids" />)'.

Edit: that’s a trick Ruud teached me. It should be added to TXB.

Last edited by maniqui (2009-02-25 15:48:16)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#211 2009-02-25 16:16:40

hamato
New Member
Registered: 2009-02-21
Posts: 9

Re: smd_if: Generic multiple if condition tests

No difference. :( That trick does work, but sort='FIELD(ID,<txp:variable name="ids" />)' and sort="custom_9 asc" are giving same results (as expected when I think about it). The moment I add a sort attribute to article_customlimit and offset gets broken. Or at least, they are not working as I would want. I don’t know why exactly.

Thanks anyway for trying to help me. Much appreciated. I’m feeling bad for spamming this thread about stuff that is not that much related to smd_if…. or it is? Maybe I should start a new topic in “How Do I…? & Other Questions” section. (edit: and I did… )

Sometimes simple thing make you spend hours and hours working. :(

Last edited by hamato (2009-02-25 19:41:33)

Offline

#212 2009-03-20 17:56:56

kostas45
Member
From: Greece
Registered: 2007-11-08
Posts: 61

Re: smd_if: Generic multiple if condition tests

Hi,

This is probably a stupid question, but here it is:

How do I access $_POST[ ] variables?
I can access $_GET[ ] variables with urlvar:var_name, but what about post variables?

Thanks,
Kostas

Offline

#213 2009-03-20 19:43:15

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

Re: smd_if: Generic multiple if condition tests

kostas45 wrote:

How do I access $_POST[ ] variables?

Not a stupid question at all because the plugin, ahem *cough* can’t access them. It’s a ridiculous oversight on my part and I can’t believe it’s taken over a year for someone to notice! Thanks for spotting it.

For the vageuly interested I started out using TXP’s built-in gps() function which grabs either POST or GET, but if neither exist it sets an empty value (the ‘s’ of gps). When trying to testi if a value has been used (at all) this is no good, so I ripped out the gps() calls and replaced them with (albeit unsafe) $_GET calls. And promptly forgot to add $_POST as well. D’oh!

I’ll have it fixed in no time. Here is some hold music…


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

#214 2009-03-20 20:36:51

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

Re: smd_if: Generic multiple if condition tests


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

#215 2009-03-21 09:25:19

kostas45
Member
From: Greece
Registered: 2007-11-08
Posts: 61

Re: smd_if: Generic multiple if condition tests

Excellent, works like a charm!
Thanks a lot Stef :-)

Cheers,
Kostas

Offline

#216 2009-03-22 11:10:14

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

Re: smd_if: Generic multiple if condition tests

Hi Stef,

Having great time with your indispensable smd_if, thanks.

Now that we’re all doing lovely tags within tags, there’s an increased danger of whitespace creeping in where you don’t expect it. This might lead to problems, for example:

<txp:variable name="x" value=" 9 " />
<txp:variable name="y" value="1" />
<txp:smd_if field="txpvar:x" operator="lt" value="txpvar:y">
<txp:variable name="x"/> is less than <txp:variable name="y"/>
</txp:smd_if>

Note the spaces around the x variable’s value. This interferes with the “less than” comparison & things go awry. Is this something that smd_if could cater for or do we just need to be very careful?

Cheers,

Adi

Offline

Board footer

Powered by FluxBB