In db.py I defined the following table:

db.define_table('cardfunction',

Field('company_id',db.company,default='',notnull=True,unique=True),
    Field('home',type='boolean',default=True),
    Field('logo',type='boolean',default=False),
    Field('tagline',type='boolean',default=False),
    Field('image',type='boolean',default=False),
    Field('css',type='boolean',default=False),
    Field('customcss',type='boolean',default=False),
    Field('keywords',type='boolean',default=False),
    migrate=False)

Based on this table I would like to generate a menu. In a controller I
got the following code:

if not session.id or session.id!=auth.user.bedrijf_id:
    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')]]


In the view I would like to generate a menu, in which, if the
session.row.field value is true a link is being rendered and if
session.row.field is false a <h4></h4> element is being rendered. What
I had in mind:

<ul>
  {{for _name,_active,_link in session.card_menu:}}
    {{if session.row.home:}}
      <li>
        <a {{if _active:}} class="active" {{pass}}
href="{{=_link}}">{{=_name}}</a>
      </li>
    {{else:}}
      <li>
        {{=_name}}
      </li>
    {{pass}}
     ....
  {{pass}}
</ul>

... doesn't work. Besides, if session.row.home: seven times, once for
every field isn't a very elegant solution either. I hope one of you
can provide me with a solution.

Kind regards,

Annet.

Reply via email to