Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#196 2008-11-22 14:36:17

roelof
Member
Registered: 2005-03-27
Posts: 647

Re: smd_if: Generic multiple if condition tests

No, according to what i thought that’s not a random else.

First i look if month = 2004-05 if it’s not then i look if month=2005-05 and if it’s also not then if month is declared.
It’s another month.
So in my opion i need this to look if month is not 2005-05 and also not 2005-05.

If i delete this else txp can’t make a difference between 2005-02 and all the months i didn’t declare because they fitt on one page.

Here’s a tag trace to illustrate this :

<txp:smd_if field="urlvar:month" operator="eq" value="2005-05">
				[<txp:smd_if field="urlvar:month" operator="eq" value="2005-05">: true]
				<txp:article limit="2" form="dagboek" sort="Posted asc" />
					[SQL (0,000226020812988): select name from txp_section where on_frontpage != '1']
					[SQL (0,000527143478394): select count(*) from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = 0) and (Category1 IN ('zwangerschap') or Category2 IN ('zwangerschap')) and Posted like '2005-05%' and Section != 'about' and Section != 'contact' and Section != 'gallery' and Section != 'voorpagina']
					[SQL (0,00105500221252): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = 0) and (Category1 IN ('zwangerschap') or Category2 IN ('zwangerschap')) and Posted like '2005-05%' and Section != 'about' and Section != 'contact' and Section != 'gallery' and Section != 'voorpagina' order by Posted asc limit 0, 2]
					[artikel 15]
					[SQL (0,000202894210815): select Form from txp_form where name='dagboek']
					[Module: dagboek]
					<txp:posted format="%B" />
					<txp:posted format= "%d" />
					<txp:title />
					<txp:body />
					[artikel 16]
					[Module: dagboek]
					<txp:posted format="%B" />
					<txp:posted format= "%d" />
					<txp:title />
					<txp:body />
				<txp:ob1_pagination outputlastfirst ="0" outputnextprevious="0" />
			</txp:smd_if>
			<txp:article limit="5" form="dagboek" sort="Posted asc" />

Roelof

Last edited by roelof (2008-11-22 14:54:51)

Offline

#197 2008-11-22 14:46:57

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,427
Website GitHub

Re: smd_if: Generic multiple if condition tests

roelof wrote:

No, according to what i thought that’s not a random else.

In which case, the <txp:smd_if /> on line 13 is in the wrong place. You can’t have a <txp:else /> outside a corresponding conditional; it must be between a pair, so check through your code and make sure that is the case.

If I write it out like this and match up the pairs you’ll see what I mean:

<txp:smd_if field="urlvar:month" operator="eq" value="2005-05">   <------------ IF #1
   <txp:article limit="2" form="dagboek" sort="Posted asc" />
   <txp:ob1_pagination outputlastfirst ="0" outputnextprevious="0" />
</txp:smd_if>   <------------ END IF #1

         <txp:else />   <------------ THIS ELSE IS NOT BETWEEN AN OPENING/CLOSING smd_if PAIR

<txp:smd_if field="urlvar:month" operator="defined">   <------------ IF #2
   <txp:article limit="5" form="dagboek" sort="Posted asc" />
</txp:smd_if>   <------------ END IF #2

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#198 2008-11-22 16:40:45

roelof
Member
Registered: 2005-03-27
Posts: 647

Re: smd_if: Generic multiple if condition tests

Hai bloke,

Im now totally confused.
What i want is a script what does this.

If month=2004-04 then if page is greater or egual as 2 then 2 articles must shown.
If month=2004 -04 and the page is not 2 or greater then 1 articles.
If month=2005-05 then 2 articles must be shown.
if another month then all the articles of that month must be shown.
If no month then it must be the frontpage then the article of the section frontpage must be schown.

Can you help me making such a script.

Roelof

Offline

#199 2008-11-22 19:32:40

roelof
Member
Registered: 2005-03-27
Posts: 647

Re: smd_if: Generic multiple if condition tests

hello Bloke,

I made a picture how i think the smd-if must look like.
Is this a correct decision tree or have i made a error.

The picture can be found at : http://plaatje.tamarawobben.nl/decision.jpg

Regards,

Roelof

Offline

#200 2008-11-23 07:54:27

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,427
Website GitHub

Re: smd_if: Generic multiple if condition tests

roelof wrote:

Is this a correct decision tree or have i made a error.

Well you haven’t specified what should happen if the section is NOT articles but if we ignore that…

<txp:if_section name=", default">
  // frontpage article
<txp:else />
   <txp:if_section name="articles">
      <txp:smd_if field="urlvar:month" operator="eq" value="2005-04">
         <txp:smd_if field="urlvar:pg" operator="ge" value="2">
            // Show one article
         <txp:else />
            // Show 2 articles
         </txp:smd_if>
      <txp:else />
         <txp:smd_if field="urlvar:month" operator="eq" value="2005-05">
            // Show 2 articles
         <txp:else  />
            // Show all articles
         </txp:smd_if>
      </txp:smd_if>
   <txp:else />   
      // You don't say what should happen here in your drawing
   </txp:if_section>
</txp:if_section>

Don’t just copy it and use it blind (it’s untested for starters) but try and understand the logic behind it. Trace it through and work out what’s going on at each line compared to your drawing. Pay particular attention to how everything is indented so that all the corresponding tags and <txp:else /> statements line up. If you lay your code out like this, it makes it easier to spot any out-of-place tags or dangling else tags (it is difficult to see this in forms and pages because the text wraps in the textarea box, but copying your template into a text editor, editing it there and then pasting the final thing back into TXP helps me in these situations).

BTW, all this seems very specific to a particular date and section. It’s not very extensible and I’m sure your logic could be optimized somewhere…


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#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: 12,427
Website GitHub

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. Bleeding-edge code available on GitHub.

Hire 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: 12,427
Website GitHub

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. Bleeding-edge code available on GitHub.

Hire 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,410

Re: smd_if: Generic multiple if condition tests

Thanks ;)

Offline

#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: 12,427
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.

Hire 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

Board footer

Powered by FluxBB