Textpattern Forum

You are not logged in. Register | Login | Help

#201 2008-12-01 20:06:43

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: smd_if: Generic multiple if condition tests

Moved post to another thread :) (Block – you can move your own here too)

Some features:
1. Check images width \ height ?
2. Check for file’s extension. I think this should work as modifier, like this: <txp:smd_if field=“txpvar:file_name” operator=“eq:EXT” value=“doc”></txp:smd_if>

P.S. Sorry for messing :)


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#202 2008-12-01 20:16:19

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

Re: smd_if: Generic multiple if condition tests

the_ghost wrote:

Check images width \ height ?

I don’t think this will be possible until some form of image context is included in TXP. For example, how would you know which image to test? There is (currently) no such concept as “current image” (unlike current article, current file, current link, which all exist right now).

However, if you try out the image patch you will get this functionality and can actually use smd_if right now by, say, assigning an image’s width or height to a txp:variable and testing if it is gt, lt or eq a value. Or using tag-in-tag to put the output of <txp:image_size /> directly into the field attribute.

Check for file’s extension

Not necessary because you can use operator="ends" value="doc".

Last edited by Bloke (2008-12-01 20:17:27)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#203 2008-12-03 00:03:56

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

Re: smd_if: Generic multiple if condition tests

A couple of new features in this upgrade.

v0.75 | compressed adds:

  • Operator divisible (thanks gomedia)
  • Ability to short circuit the field so you only need to specify it once if you are comparing many things to a single field (thanks redbot)

Example 6 in the help demonstrates the latter, and here’s a quick example of how you might use the former:

<txp:smd_gallery category="pics">
   <txp:smd_if field="{counter}" operator="divisible" value="2">
      <txp:image id="{id}" class="even" />
   <txp:else />
      <txp:image id="{id}" class="odd" />
   </txp:smd_if>
</txp:smd_gallery>

Stripe-tastic :-)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#204 2008-12-03 10:53:07

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,398

Re: smd_if: Generic multiple if condition tests

Thanks ;)

Online

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

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.

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
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 2,975
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
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 2,975
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

Board footer

Powered by FluxBB