Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#151 2008-11-15 15:47:14

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

Re: smd_if: Generic multiple if condition tests

roelof wrote:

If month=2005-04 and there’s no page (http://test2.tamarawobben.nl/?c=zwangerschap&month=2005-04) then show one article.
and after that i want if month=2005-04 and page=2 then show 3 articles.

Then you’ll need something like:

<txp:smd_if field="urlvar:month, urlvar:pg" operator="eq,undefined" value="2005-04">
 // Show one article here
<txp:else />
  // Show 3 articles here
</txp:smd_if>

EDIT: but also remember that the ‘else’ will be executed if the month variable is something other than 2005-04

Last edited by Bloke (2008-11-15 15:55:04)


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

#152 2008-11-15 18:01:08

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: smd_if: Generic multiple if condition tests

OK, this is interesting….

I routinely use mdp_calendar to build cals on installs…

One of the problems I have is that a link from a small calendar will lead to a date based url. I have not found a way to gracefully distinguish between a single article and an article list (one event that day or two.) So that if it’s a single article it displays <txp:body/> and if it’s a list display <txp:excerpt/>.

The best I’ve come up with is to always display the first article in full and thereafter as excerpts.

Any other Text-Fu? Come on chumpus, go purple.

Offline

#153 2008-11-15 19:03:31

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

Re: smd_if: Generic multiple if condition tests

oke,

If i understand it right :

if month=“2004-05” and pg is not defined or pg=1

i do this :

<txp:smd_if field=“urlvar:month, urlvar:pg, urlvar:pg” operator=“eq,undefined,eq” logic=“and”,“or” value=“2005-04”,“1”>

Roelof

Offline

#154 2008-11-15 19:26:59

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

Re: smd_if: Generic multiple if condition tests

roelof wrote:

<txp:smd_if field=“urlvar:month, urlvar:pg, urlvar:pg” operator=“eq,undefined,eq” logic=“and”,“or” value=“2005-04”,“1”>

Nope. You can only do one type of logic at a time, sorry. You have to choose either AND (the default) or logic="or" to switch it. I did consider allowing multiple logic types (see an earlier post by the_ghost) but it was very complicated and I abandoned the idea. Especially since nested smd_if calls are going to be allowed in TXP 4.0.7.

Under TXP 4.0.6, what you are trying to do is pretty tricky and I can’t think of a way of doing it without resorting to some <txp:php> inside the <txp:smd_if> tag.

mrdale

Interesting indeed, but bad news for you as well: I can’t find a variable anywhere on the page that would allow me to test that condition. If it ain’t on the page, I can’t check it :-(

I wondered if $thispage had anything useful (like, if the calendar used it to store the total number of results that matched the current date) but for some reason I can’t even display the contents of it on my SVN test site; I just get back NULL all the time. Clearly I don’t understand what it does, despite trying this! I’ll delve a bit deeper, but at the moment it’s no no mojo from the chumpstick right now.

Last edited by Bloke (2008-11-15 19:27:35)


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

#155 2008-11-15 20:05:29

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: smd_if: Generic multiple if condition tests

chumperoo> Thanks. You are a man among chumps, indeed.

Offline

#156 2008-11-15 20:45:12

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

Re: smd_if: Generic multiple if condition tests

Hello Bloke,

Thank you for your time.
If this is not possible it no big deal.

Roelof

Offline

#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

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

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.

Hire 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

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

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.

Hire 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

Board footer

Powered by FluxBB