Textpattern CMS support forum

You are not logged in. Register | Login | Help

#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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,787
Website

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,226
Website

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,787
Website

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:

  1. pg is set to something
  2. 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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,787
Website

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,226
Website

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

#169 2008-11-19 11:46:07

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

Re: smd_if: Generic multiple if condition tests

Hoi Bloke,

Your idea isn’t working properly.
Page 1 is displayed well.
Page 2 is blank.

This is my 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” operator=“eq” value=“2005-04> <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>

And this is the tag trace :

<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:smd_if field=“urlvar:month, urlvar:pg” operator=“eq,eq” value=“2005-04, 1”> [<txp:smd_if field=“urlvar:month, urlvar:pg” operator=“eq,eq” value=“2005-04, 1”>: false] <txp:article limit=“3” form=“dagboek” sort=“Posted asc” /> [SQL (0,000254154205322): select name from txp_section where on_frontpage != ‘1’] [SQL (0,000365972518921): 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-04%’ and Section != ‘about’ and Section != ‘contact’ and Section != ‘gallery’] [SQL (0,00075888633728): 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-04%’ and Section != ‘about’ and Section != ‘contact’ and Section != ‘gallery’ order by Posted asc limit 3, 3] <txp:ob1_pagination outputlastfirst =“0” outputnextprevious=“0” /> </txp:smd_if>
</txp:smd_if>

As far i can see the right article form is working nl 3 articles a page but on the page i see nothing.

Roelof

Offline

#170 2008-11-19 11:57:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,787
Website

Re: smd_if: Generic multiple if condition tests

roelof wrote:

Your idea isn’t working properly.

Are you sure? Pay attention to the details and try adding the missing quote around the value in the following line:

      <txp:smd_if field="urlvar:month" operator="eq" value="2005-04>

Then see what you get back.

(Edit: could you try and add bc. in front of your code blocks in future posts please, it’s quite hard to trace it when it’s one continuous stream of stuff on the screen, thanks!)

Last edited by Bloke (2008-11-19 11:58:25)


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

Board footer

Powered by FluxBB