Textpattern CMS support forum

You are not logged in. Register | Login | Help

#191 2008-11-21 01:17:58

maniqui
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_if: Generic multiple if condition tests

Very very clever. I liked it. :)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#192 2008-11-21 02:00:28

nabrown78
Member
From: Boston, MA, USA
Registered: 2006-10-04
Posts: 289
Website

Re: smd_if: Generic multiple if condition tests

Wow. How the hell did you figure that out? I’m going to have to think on that code some more…
I just got wise to txp:variable today – it’s only in the soon-to-be-released 4.0.7, right? Are there any docs anywhere about how this guy works? I read through the orig. forum thread. Can you set it in the admin interface as well? Or only in page templates, forms, etc?

Bloke thanks for your help on this…I guess I should look at the smd_query you recommend too!

Offline

#193 2008-11-21 09:51:52

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

Re: smd_if: Generic multiple if condition tests

nabrown78 wrote:

Wow. How the hell did you figure that out?

Hehe, equal measures of luck and being a geek I guess. If someone gives me a tool, I find a way to (ab)use it ;-)

I just got wise to txp:variable… Are there any docs anywhere about how this guy works?

You are correct, it’s a 4.0.7 feature. That code I posted would be nigh on impossible without the new parser (or dropping into PHP). As for docs, the forum thread you found and also one on empty vars have good tips in them. In addition, there’s the TXPQ interview with the tags that I wrote. It contains a few techie gremlins (kindly pointed out in the comments below the article) but gives some more grounding in how to use the tags.

Can you set it in the admin interface as well? Or only in page templates, forms, etc?

Well, it’s a public tag so Forms and Pages are where it normally resides. If you want something more permanent, check out the not-quite-as-full-featured-as-I-hoped-but-still-useful smd_vars. There are a few mini bugs still to fix (must get round to it one day) and it needs expanding in scope a little, but it’s stable enough to play with.

I guess I should look at the smd_query you recommend too!

Recommend is perhaps over-selling it. Last resort is probably better ;-) But by all means take a look if you’re an SQL afficionado. Thinking about it again I’m not sure it’ll help because it (currently) cannot take stuff from the URL line so couldn’t grab the ?q= thing that the person searched for. Future versions may offer this ability and then it’d be a cinch to use.


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

#194 2008-11-22 13:16:35

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

Re: smd_if: Generic multiple if condition tests

hai Bloke,

I need your help one more time :

I have made this :

<txp:smd_if field="urlvar:month" operator="eq" value="2005-04">
       <txp:smd_if field="urlvar:pg" operator="ge" value="2">
              <txp:article limit="2" form="dagboek" sort="Posted asc" />
              <txp:ob1_pagination outputlastfirst ="0" outputnextprevious="0" />
          <txp:else />
            <txp:article limit="1" form="dagboek" sort="Posted asc" />
            <txp:ob1_pagination outputlastfirst ="0" outputnextprevious="0" maximumtabs="4"/>
        </txp:smd_if>
<txp:else />   <-----------------------------------------------------------------------------------------------------
       <txp:smd_if field="urlvar:month" operator="eq" value="2005-05">
         <txp:article limit="2" form="dagboek" sort="Posted asc" />
              <txp:ob1_pagination outputlastfirst ="0" outputnextprevious="0" />
         </txp:smd_if>
         <txp:else />
     <txp:smd_if field="urlvar:month" operator="defined"> <-----------------------------------------------------
              <txp:article limit="5" form="dagboek" sort="Posted asc" />
    </txp:smd_if>
</txp:smd_if>

But txp keeps complening about the else between the <———
So you see why ?

Roelof

Offline

#195 2008-11-22 13:59:24

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

Re: smd_if: Generic multiple if condition tests

You have a random, extra <txp:else /> on line 14 of the code you posted above. Remove that and it’ll stop complaining.


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

#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: 8,629
Website

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.

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: 8,629
Website

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.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB