Hi Annet,
On Mar 22, 10:08 am, annet <[email protected]> wrote:
> Thanks for your reply. I had a look at the code, but I am afraid it
> doesn't solve my problem. The functions are fields in a table and
> depending on their value being true or false they should be rendered
> as an <a></a> or <h4></h4> element.
>
> Given this code in a function:
>
> session.id=auth.user.bedrijf_id
> session.row=db(db.cardfunction.bedrijf_id==session.id).select(db.cardfunction.ALL)
> session.card_menu=[
> ['Home',request.function=='index',URL(r=request,f='index')],
> ['Logo',request.function=='logo',URL(r=request,f='logo')],
> ...
>
> ['Keywords',request.function=='keywords',URL(r=request,f='keywords')]]
>
> .. I am looking for a way to make use of the _name attribute, for this
> is the same as the field name, something like:
>
> <ul>
> {{for _name,_active,_link in session.card_menu:}}
> {{if session.row._name:}}
> <li>
> <a {{if _active:}} class="active" {{pass}}
> href="{{=_link}}">{{=_name}}</a>
> </li>
> {{else:}}
> <li>
> <h4 class="disabled">{{=_name}}</h4>
> </li>
> {{pass}}
> {{pass}}
> </ul>
>
> The problem is that this: {{if session.row._name:}} results in a
> KeyError '_name'
> Is it possible to use _name to accomplish this?
I think you want
{{if session.row[0][_name.lower()]:}}
session.row is a Rows object, not a single row, so you have to select
the first one, hence [0].
The single row will have the _name key.
Since your menu is using the capitalized version of the field name I
added _name.lower() so that it would get the correct field name.
> Kind regards,
>
> Annet.