Edgewall Software

Ticket #7418 (new defect)

Opened 2 months ago

Active navigation items are broken in Clearsilver templates

Reported by: anonymous Owned by:
Priority: normal Milestone:
Component: general Version: 0.11-stable
Severity: normal Keywords:
Cc:

Description

It looks like changes made to move templates away from Clearsilver have introduced a regression where active navigation items are not highlighted properly.

To reproduce, use a plugin that returns a Clearsilver template from its process_request() method. You will see that the "mainnav" navigation bar does not render the active item highlighted.

The bug is that the CSS class "active" is not assigned to the list element in the navigation bar.

The fix is to change trac/web/chrome.py:

class Chrome(component)
...
    def populate_hdf(self, req):
    ...
        for category, items in req.chrome['nav'].items():
+           req.hdf['chrome.nav.%s' % category] = items
-           for item in items:
-               prefix = 'chrome.nav.%s.%s' % (category, item['name'])
-               req.hdf[prefix] = item['label']

And then change trac/templates/header.cs:

<?cs def:nav(items) ?><?cs
 if:len(items) ?><ul><?cs
  set:idx = 0 ?><?cs
  set:max = len(items) - 1 ?><?cs
  each:item = items ?><?cs
   set:first = idx == 0 ?><?cs
   set:last = idx == max ?><li<?cs
   if:first || last || item.active ?> class="<?cs
    if:item.active ?>active<?cs /if ?><?cs
    if:item.active && (first || last) ?> <?cs /if ?><?cs
    if:first ?>first<?cs /if ?><?cs
    if:(item.active || first) && last ?> <?cs /if ?><?cs
    if:last ?>last<?cs /if ?>"<?cs
+  /if ?>><?cs var:item.label ?></li><?cs
-  /if ?>><?cs var:item?></li><?cs
   set:idx = idx + 1 ?><?cs
  /each ?></ul><?cs
 /if ?><?cs
/def ?>

Attachments

Add/Change #7418 (Active navigation items are broken in Clearsilver templates)

Author



Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will change. Next status will be 'new'
The owner will change to anonymous. Next status will be 'assigned'
 
Note: See TracTickets for help on using tickets.