Prev: [ANNOUNCEMENT] HTML_Template_Flexy-1.3.10 (stable) Released.
Next: QuickForm2 (rules involving to objects)
From: Jamie Kahgee on 7 Jun 2010 11:51 If I wanted to apply an id/class to the last parent item in a menu - is it possible w/out modifying this script? I'm using the HTML_Menu_DirectTreeRenderer and need a marker on the last <li> in the main list ie: <ul> <li>Menu item 1 <ul> <li>Menu item 1.1</li> <li>Menu item 1.2</li> </ul> </li> <li* id="lastli"*>Menu item 2</li> <-- need to add class here </ul> Thanks, Jamie K.
From: Richard Quadling on 7 Jun 2010 18:56 On 7 June 2010 16:51, Jamie Kahgee <jamie.kahgee(a)gmail.com> wrote: > If I wanted to apply an id/class to the last parent item in a menu - is it > possible w/out modifying this script? > > I'm using the HTML_Menu_DirectTreeRenderer and need a marker on the last > <li> Â in the main list > > ie: > > <ul> > Â Â <li>Menu item 1 > Â Â Â Â <ul> > Â Â Â Â Â Â <li>Menu item 1.1</li> > Â Â Â Â Â Â <li>Menu item 1.2</li> > Â Â Â Â </ul> > Â Â </li> > Â Â <li* id="lastli"*>Menu item 2</li> Â <-- need to add class here > </ul> > > > > Thanks, > Jamie K. > You could use JavaScript ... $$('ul li').last().id = 'lastli' Maybe. (Using prototype.js for that). But I'm not 100% sure on what order the CSS selectors would give up the list. Maybe ... $$('ul').first().select('li').last() -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling
From: Jamie Kahgee on 7 Jun 2010 19:34 Thanks for the answer. Unfortunately I needed to tackle this w/out CSS selectors or JS, or I totally would have taken the route you suggested. What I ended up doing was subclassing the HTML_Menu_DirectTreeRenderer and overridding the finishMenu method. now I just pass in the new subclass for the renderer and the new method looks like this: function finishMenu($level) { parent::finishMenu($level); // $this->_id is now set via the class constructor if (!is_null($this->_id)) { $dom = new DOMDocument(); $dom->loadHTML($this->_html); $uls = $dom->getElementsByTagName('ul'); $ul = $uls->item(0); $ul->lastChild->setAttribute('id', $this->_id); // Prevent tags and doctype from being added to the HTML // string automatically. $this->_html = substr($dom->saveXML( $dom->getElemebtsByTagName('ul')->item(0) ), 0); } } Thanks, Jamie K. On Mon, Jun 7, 2010 at 6:56 PM, Richard Quadling <rquadling(a)gmail.com>wrote: > On 7 June 2010 16:51, Jamie Kahgee <jamie.kahgee(a)gmail.com> wrote: > > If I wanted to apply an id/class to the last parent item in a menu - is > it > > possible w/out modifying this script? > > > > I'm using the HTML_Menu_DirectTreeRenderer and need a marker on the last > > <li> in the main list > > > > ie: > > > > <ul> > > <li>Menu item 1 > > <ul> > > <li>Menu item 1.1</li> > > <li>Menu item 1.2</li> > > </ul> > > </li> > > <li* id="lastli"*>Menu item 2</li> <-- need to add class here > > </ul> > > > > > > > > Thanks, > > Jamie K. > > > > You could use JavaScript ... > > $$('ul li').last().id = 'lastli' > > Maybe. > > (Using prototype.js for that). > > But I'm not 100% sure on what order the CSS selectors would give up the > list. > > Maybe ... > > $$('ul').first().select('li').last() > > > > -- > ----- > Richard Quadling > "Standing on the shoulders of some very clever giants!" > EE : http://www.experts-exchange.com/M_248814.html > EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp > Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 > ZOPA : http://uk.zopa.com/member/RQuadling >
From: Alexey Borzov on 8 Jun 2010 04:28
Hi Jamie, On 07.06.2010 19:51, Jamie Kahgee wrote: > If I wanted to apply an id/class to the last parent item in a menu - is it > possible w/out modifying this script? > > I'm using the HTML_Menu_DirectTreeRenderer and need a marker on the last > <li> in the main list > > ie: > > <ul> > <li>Menu item 1 > <ul> > <li>Menu item 1.1</li> > <li>Menu item 1.2</li> > </ul> > </li> > <li* id="lastli"*>Menu item 2</li> <-- need to add class here > </ul> The Renderer will substitute any custom keys you add to the menu element array. If you set item template to <li{attributes}>, </li> and then pass an array containing key ('attributes' => ' id="lastli"') as the last element on level, the output will be as above. |