All this discussion of yet more "<r:if_x>" tags and another recent thread with the desire to pass values to snippets has me thinking of digging up my old conditional/variables extension. I'm sure it needs revamped for the current versions of Radiant and I'd like to clean up the syntax some but, mostly, I'd like to know if folks out there would find it useful...

Here's what I'm thinking. Please let me know if it'd be helpful to you, if you have any suggestions, and if you'd be interested in contributing:

  1. General conditional statements.  For instance, instead of solving
     this post's problem by creating a new tag (more tags for our users
     to learn), with a syntax different than the other <r:if_x> (also
     complicating things for them), we'd simply have a single <r:if>
     tag so you could write: <r:if cond="children.index = 1">.

     The <r:if> tag already knows how to parse the cond attribute, and
     how to evaluate the condition (true, false, greater than, string
     compare, regexp matching, etc) so you don't have to rewrite the
     logic every time.  To solve this problem, all that would be needed
     is to tell it how to evaluate "children.index" (or some such
     notation).  Currently I have implemented:
         * page.url
         * page.title
         * page.slug
         * page.breadcrumb
         * page.children.count
         * page.part[part_name]
         * vars[my_variable_name] (more on this in point #2)

  2. Ways to get/set basic variables.  For this one I had created a
     <r:store /> tag that could be used like:
         <r:store vars="my_var1: 'some string text'; my_var2: 100;
     my_var3: false />
         <r:puts value_for="vars[my_var1]" />   -->  "some string text"

     You could also use puts with the above like...
         <r:puts value_for="page.children.count" />  (not sure how
     useful this is...)

     Where it got nice though is using it with the conditionals like:
       ---- in page ----
         <r:store vars="linkText: 'Some example link text'; url:
             class: myClass" />
         <r:snippet name="link" />

       ---- in snippet ----
         <a href="<r:puts value_for="vars[url]" />"
         <r:if cond="vars[class]"> class="<r:puts
     value_for="vars[class]" />"</r:if>>
           <r:puts value_for="vars[linkText]" />

     I had also implemented a modified <r:snippet> tag to make the
     first part easier so you could just do:
       ---- in page ----
         <r:snippet name="link" vars="linkText: 'Some example link
     text'; url: my/target/url;
           class: myClass" />

Ok, so that's a long explanation. I'm happy to resurrect the extension, but the big question is would this (or something similar) be useful?

Let me know...


John W. Long wrote:
On Jun 26, 2008, at 8:36 AM, Jim Gay wrote:
I think it should allow a "group" or "size" option.

<r:if_first size="3"> would apply to the first 3. Working with more than just one would be useful.

I would want to have these tags with that option:
if_first / unless_first
if_last / unless_last

I'm not sure about the name of the parameter though. Perhaps <r:if_first window="3">

How about:

<r:if_index in="1,2,3">    # if it's one of the first 3 children
<r:if_index in="-1,-2,-3"> # if it's one of the last 3 children
<r:if_index is="1">        # equivalent to <r:if_first />
<r:if_index is="-1">       # equivalent to <r:if_last />
<r:if_index is="even">     # if it's an even row
<r:if_index is="odd">      # if index is an odd row

Seems like a 1 based index would be most helpful here.

John Long
Radiant mailing list

Radiant mailing list

Reply via email to