Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#157 2008-11-15 23:24:51
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: smd_if: Generic multiple if condition tests
(Stef, sorry for abusing your plugin thread, but) Roelof, if all you need to do is check if it’s the first page or not, wouldn’t wet_if_page be a better and simpler way to do that?
Offline
#158 2008-11-16 11:40:08
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: smd_if: Generic multiple if condition tests
Hello Els,
I have to check if the month is 2005-04 and if it’s then i have to check if it’s the first page of that month.
Roelof
Offline
#159 2008-11-16 11:50:47
Re: smd_if: Generic multiple if condition tests
Els is right (thank you). You can do what you ask, like this:
<txp:smd_if field="urlvar:month, urlvar:pg" operator="eq,undefined" value="2005-04">
// Show one article here
<txp:else />
<txp:wet_if_page page="1">
// Show one article here also
<txp:else />
// Show 3 articles here
</txp:wet_if_page>
</txp:smd_if>
i.e. if the month is 2005-04 and the pg is not used, you must be on the front page, thus you show one article. If, however, the page is used you enter the ‘else’ block whereby it checks to see if the page is page nmuber 1. If it is, you only show one article, if it’s not you show 3.
Thanks again Els. Nice one!
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
#160 2008-11-16 14:51:16
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: smd_if: Generic multiple if condition tests
Hai Bloke,
Your script works only i have 3 remarks.
1) The other months shows now the first article double.
2) Ob-pagination thinks on the first page that there are 5 pages and on the second page there are two pages.
3) The month 2005-04 has 7 articles nl. 1,4,5,7,11,15,24 april When using this script on page 1 i see 1 april , that’s correct. But on page 2 i see 7 and 15 april. The rest of the articles seem tot be disappear.
You can see it work at : http://test2.tamarawobben.nl
Regards,
Roelof
Last edited by roelof (2008-11-16 14:56:34)
Offline
#161 2008-11-18 11:31:28
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: smd_if: Generic multiple if condition tests
Hello,
Can 4.0.7 with nested tags and adi_gps together with this plugin be a solution ?
If so, it is difficult to use svn for a live website ?
Roelof
Offline
#162 2008-11-18 11:51:10
Re: smd_if: Generic multiple if condition tests
roelof wrote:
Can 4.0.7 with nested tags and adi_gps together with this plugin be a solution ?
Yes, very much so. Adi’s my hero today :-)
Under 4.0.7 you could do it without Adi’s plugin because you can nest the smd_if calls and make up complex layers of conditionals that successively filter your data until you reach the desired action. But using adi_gps means you can take advantage of the decode
option (if necessary). If you do use adi_gps you can also rename the variables if you wish and use smd_if to get at them like this: field="txpvar:my_renamed_variable"
. It may not be necessary in this case but it’s certainly a nice feature to make your smd_if calls a little tidier!
If so, it is difficult to use svn for a live website ?
It’s not recommended simply because the kinks have not been ironed out. But Stuart does (and has been for ages) and he’s only found one problem with searches recently, which will be fixed soon.
If it is for a paying client I would steer clear of SVN but if it’s your own site, you might as well try it. Just make sure you backup your database and the files in your install first so it’s easier to roll back if you have to :-)
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
#163 2008-11-18 12:54:39
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: smd_if: Generic multiple if condition tests
oke,
Now the problem that ob-pagination displaying the wrong numbers of pages.
Maybe i can use then <txp:variable> but i don’t know how to use then the value in a php script as ob-pagination is.
Roelof
Offline
#164 2008-11-19 03:33:24
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
Re: smd_if: Generic multiple if condition tests
Bloke wrote:
Yes, very much so. Adi’s my hero today :-)
Blimey … you’re very kind.
Reason for the call is that I’ve made a Feature idea suggestion txp:variable increment & decrement and if it gets wings then how about an enhancement to smd_if to add a new operator “is divisible by” which would test whether a supplied number is divisible by a given divisor.
For example, this would help if you wanted to do zebra stripes (divisible by 2: i.e. even or odd).
And implementing a matrix/grid/table would be easier as well (e.g. if count is divisible by row length, then do something different).
Or maybe it should be some sort of modulo operation (i.e. remainder of zero = “is divisible by”)?
Offline
#165 2008-11-19 09:00:27
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: smd_if: Generic multiple if condition tests
Hoi Bloke,
this plugin is not working properly with 4.0.7.
I have this page template :
<txp:smd_if field=“urlvar:month, urlvar:pg” operator=“eq,undefined” value=“2005-04”>
<txp:article limit=“1” form=“dagboek” sort=“Posted asc” />
<txp:ob1_pagination outputlastfirst =“0” outputnextprevious=“0” />
<txp:else />
<txp:smd_if field=“urlvar:month, urlvar:pg” operator=“eq,eq” value=“2005-04”,“1”>
<txp:article limit=“1” form=“dagboek” sort=“Posted asc” />
<txp:ob1_pagination outputlastfirst =“0” outputnextprevious=“0” />
<txp:else />
<txp:smd_if field=“urlvar:month, urlvar:pg” operator=“eq,eq” value=“2005-04”,“2”>
<txp:article limit=“3” form=“dagboek” sort=“Posted asc” />
<txp:ob1_pagination outputlastfirst =“0” outputnextprevious=“0” />
</txp:smd_if>
</txp:smd_if>
</txp:smd_if>
It’s showing the articles fout times.
Here’s the tag trace:
bc. <txp:smd_if field=“urlvar:month, urlvar:pg” operator=“eq,undefined” value=“2005-04”>
[<txp:smd_if field=“urlvar:month, urlvar:pg” operator=“eq,undefined” value=“2005-04”>: false]
<txp:article limit=“1” form=“dagboek” sort=“Posted asc” />
[SQL (0,000283002853394): select name from txp_section where on_frontpage != ‘1’]
[SQL (0,000829935073853): select count(*) from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = 0) and Section != ‘about’ and Section != ‘contact’ and Section != ‘gallery’]
[SQL (0,00147986412048): 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 Section != ‘about’ and Section != ‘contact’ and Section != ‘gallery’ order by Posted asc limit 0, 1]
[artikel 2]
[SQL (0,000242948532104): select Form from txp_form where name=‘dagboek’]
[Module: dagboek]
<txp:posted format=”%B” />
<txp:posted format= “%d” />
<txp:title />
<txp:body />
<txp:upm_image type=“image” image_id=“3” class=“left” />
[SQL (0,000240087509155): select * from txp_image where id = ‘3’ limit 0, 1]
<txp:ob1_pagination outputlastfirst =“0” outputnextprevious=“0” />
<txp:else />
<txp:else /> -> Textpattern Warning: on line 1094
<txp:article limit=“3” form=“dagboek” sort=“Posted asc” />
[SQL (0,000530004501343): select count(*) from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = 0) and Section != ‘about’ and Section != ‘contact’ and Section != ‘gallery’]
[SQL (0,00128698348999): 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 Section != ‘about’ and Section != ‘contact’ and Section != ‘gallery’ order by Posted asc limit 0, 3]
[artikel 2]
[Module: dagboek]
<txp:posted format=”%B” />
<txp:posted format= “%d” />
<txp:title />
<txp:body />
<txp:upm_image type=“image” image_id=“3” class=“left” />
[SQL (0,000253915786743): select * from txp_image where id = ‘3’ limit 0, 1]
[artikel 3]
[Module: dagboek]
<txp:posted format=”%B” />
<txp:posted format= “%d” />
<txp:title />
<txp:body />
[artikel 4]
[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:smd_if>
[<txp:smd_if>: false]
</txp:smd_if>
Roelof
Offline
#166 2008-11-19 09:55:09
Re: smd_if: Generic multiple if condition tests
roelof wrote:
this plugin is not working properly with 4.0.7.
I think it might do if you get rid of the errors in your smd_if call :-) The value
attribute — just like every other attribute — can only take one list of things inside a single pair of quotes, not a set of separate things each in their own quotes. So this is more correct:
...
<txp:smd_if field="urlvar:month, urlvar:pg" operator="eq, eq" value="2005-04, 1">
<txp:article limit="1" form="dagboek" sort="Posted asc" />
<txp:ob1_pagination outputlastfirst ="0" outputnextprevious="0" />
<txp:else />
<txp:smd_if field="urlvar:month, urlvar:pg" operator="eq, eq" value="2005-04, 2">
<txp:article limit="3" form="dagboek" sort="Posted asc" />
<txp:ob1_pagination outputlastfirst ="0" outputnextprevious="0" />
</txp:smd_if>
</txp:smd_if>
...
Also, I thought you wanted to do something different only if you were on the first page? As it stands, your outer ‘else’ statement tests to see if the month
variable is set to 2005-04
and pg=1
. If that fails (indicating either the month is not 2005-04 or the pg is something higher than 1), it checks to see if the pg is equal to 2. What if it’s 3? Or 4? You’ll get no output.
You might want to consider changing that second smd_if in my example above to:
<txp:smd_if field="urlvar:month, urlvar:pg" operator="eq, ge" value="2005-04, 2">
So that it executes the contained statament if pg
is greater than or equal to 2. Better still would be this:
<txp:smd_if field="urlvar:month" operator="eq" value="2005-04">
since you already know due to the cascading logic that:
- pg is set to something
- pg is not 1
thus pg must be 2 or higher, so it is not necessary to test it. If you trace through your logic and try different numbers to see which branches execute under which conditions, you’ll find this is true. A bonus of being able to nest the same tag is that your smd_if calls can often be simplified the deeper they get.
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
#167 2008-11-19 10:01:29
Re: smd_if: Generic multiple if condition tests
gomedia wrote:
…a Feature idea suggestion txp:variable increment & decrement … how about an enhancement to smd_if to add a new operator “is divisible by”
Well, looks like it won’t be getting wings (wet’s argument makes sense and rvm_counter can do the counting for us, as maniqui says) but even so, your idea about a modulo and/or is divisible by is great. I think I can shoehorn that logic into my evil() template system; I’ll try it out when I make some time.
In the meantime, zem_nth could probably be coerced into doing the same thing, but in the interests of having one less plugin to do something that’s probably within reach of this one, I think it’s a plan.
Thanks for the idea.
Last edited by Bloke (2008-11-19 10:02:16)
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
#168 2008-11-19 11:27:08
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
Re: smd_if: Generic multiple if condition tests
Bloke wrote:
Well, looks like it won’t be getting wings …
Didn’t even get to hatch! I’ll revisit the other options the next time I need to use TXP variables as counters, in the meantime I look forward to your modulo enhancement.
All the best.
Offline