Invenzzia »

Pages: [1]   Go Down
  Print  
Author Topic: OPTv2: Appending or Multiple values for an attribute  (Read 636 times)
0 Members and 1 Guest are viewing this topic.
duclet
User

Offline Offline

Posts: 8


View Profile
« on: November 27, 2009, 23:06:45 »

In constructing my menu, I want to be able to have code which would do something similar to the following:

Code:
<a href="...">
<opt:attribute name="class" value="last" opt:if="$menu.is_last" />
<opt:attribute name="class" value="active" opt:if="$menu.active" />
Link Text
</a>

Obviously that doesn't work because I can't redeclare the same attribute. I can't wrap the entire thing around an if block either since the parent won't be the anchor tag anymore. Is there any way to append the values?
Logged
Zyx
Your programmer
Administrator
User
*****
Offline Offline

Posts: 291



View Profile WWW
« Reply #1 on: November 28, 2009, 08:38:18 »

Yes, of course. Take a look at this:

Code:
<a href="...">
<opt:attribute str:name="class">
    <opt:value test="$menu.is_last">last</opt:value>
    <opt:value test="$menu.is_active">active</opt:value>
</opt:attribute>
Link Text
</a>

Just note that there was a small bug in the implementation - if none of the conditions was true, the instruction still generated the empty tag: <a class=""> (where it should not generate any in this case). It is fixed in SVN right now and if you like, you can download the fixed code from there.
Logged

PozDrX, Zyx
---Invenzzia group---
duclet
User

Offline Offline

Posts: 8


View Profile
« Reply #2 on: November 28, 2009, 16:24:58 »

But would that append to the value? So if the last item in the menu is also the active item, it would become "last active"?
Logged
Zyx
Your programmer
Administrator
User
*****
Offline Offline

Posts: 291



View Profile WWW
« Reply #3 on: November 29, 2009, 08:29:49 »

Then you can do:

Code:
<a href="...">
<opt:attribute str:name="class">
    <opt:value test="$menu.is_active and $menu.is_last">last active</opt:value>
    <opt:value test="$menu.is_last">last</opt:value>
    <opt:value test="$menu.is_active">active</opt:value>
</opt:attribute>
Link Text
</a>

The true appending will be possible in OPT 2.1 which will contain the swiss knife: opt:switch.
Logged

PozDrX, Zyx
---Invenzzia group---
duclet
User

Offline Offline

Posts: 8


View Profile
« Reply #4 on: November 30, 2009, 00:41:01 »

Yup, I am currently doing that. I was hoping there was a more efficient way. Well, can't wait until the 2.1 release. Thanks.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Subject Started by Replies Views Last post
abercrombie italia, and held several meetings galardef 0 18 Last post April 18, 2012, 04:46:59
by galardef
OPTv2: nested sections whumble 1 296 Last post November 07, 2010, 08:19:25
by Zyx
OPTv2: Filtrowanie XSS Nowaker 6 1230 Last post January 06, 2009, 10:57:24
by Zyx
OPTv2: Main tpl parced but opt:include view not parce amichelin 5 1969 Last post May 03, 2009, 16:03:37
by eXtreme
OPT: About plugins turbex 7 2084 Last post August 22, 2008, 19:58:13
by Zyx