Forum OpenACS Development: conditional property

Collapse
Posted by Vinod Kurup on
I have 2 different items that I may or may not want to put in the <property name="header_stuff"> tag at the top of an ADP page. Each of the items should be present only if a certain condition is true.

I tried the obvious first:

<property name="header_stuff">
<if @condition_1@>Item 1</if>
<if @condition_2@>Item 2</if>
</property>
Unfortunately, that doesn't work since ADP tags aren't evaluated inside a <property> tag, they're just spit out to the page.

So I could either

  1. Make 4 different <property> tags and then do a complex set of if/then's to decide which one to output.
  2. Do the evaluation in the tcl page and have a simple <property name="header_stuff">@item_1@@item2@</property> tag, but this would mean putting HTML markup in the TCL file.
  3. Maybe there's a third way I'm not thinking of?
To see the real-world example, look at Weblogger's index.adp page. Someone used Method #1 to conditionally add the RSS <link>, but this could get really ugly as I I'm trying to add a conditional RSD link, which would make the if/then situation twice as complex.

I'm leaning toward Method #2 - any suggestions?

Collapse
2: Re: conditional property (response to 1)
Posted by Randy O'Meara on
An equally ugly solution...

Put tcl in the ADP page with <% ... %>

Collapse
3: Re: conditional property (response to 1)
Posted by Bart Teeuwisse on

Actually, there is a clean third way of doing this.

  1. Create an new .adp file. Let's call it headerstuff.adp containing:
    
    <if @condition_1@>Item 1</if>
    <if @condition_2@>Item 2</if>
    
  2. Call headerstuff.adp from the .tcl file you would like to use property header_stuff in:
    
    set cwd [file dirname [ad_conn file]]
    set headerstuff [template::adp_parse ${cwd}/headerstuff \
    	      [list \
    		   condition_1 $condition_1 \
    		   condition_2 $condition_2]]
    
  3. Then pass the header_stuff property like so:
    
    <property name="header_stuff">@headerstuff@</property>
    

/Bart

Collapse
4: Re: conditional property (response to 3)
Posted by Vinod Kurup on
Thanks Bart - that sounds like the best way to go.