Message from discussion
Highlighting menu based on controller called
Received: by 10.227.10.143 with SMTP id p15mr355455wbp.7.1306736455581;
Sun, 29 May 2011 23:20:55 -0700 (PDT)
X-BeenThere: symfony-users@googlegroups.com
Received: by 10.227.5.200 with SMTP id 8ls2084870wbw.1.gmail; Sun, 29 May 2011
23:20:46 -0700 (PDT)
Received: by 10.227.7.19 with SMTP id b19mr357913wbb.4.1306736446707;
Sun, 29 May 2011 23:20:46 -0700 (PDT)
Received: by 10.227.7.19 with SMTP id b19mr357912wbb.4.1306736446676;
Sun, 29 May 2011 23:20:46 -0700 (PDT)
Return-Path: <liebegr...@gmail.com>
Received: from mail-ww0-f52.google.com (mail-ww0-f52.google.com [74.125.82.52])
by gmr-mx.google.com with ESMTPS id e6si4672819wbh.3.2011.05.29.23.20.46
(version=TLSv1/SSLv3 cipher=OTHER);
Sun, 29 May 2011 23:20:46 -0700 (PDT)
Received-SPF: pass (google.com: domain of liebegr...@gmail.com designates 74.125.82.52 as permitted sender) client-ip=74.125.82.52;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of liebegr...@gmail.com designates 74.125.82.52 as permitted sender) smtp.mail=liebegr...@gmail.com; dkim=pass (test mode) header...@gmail.com
Received: by wwb31 with SMTP id 31so3012043wwb.33
for <symfony-users@googlegroups.com>; Sun, 29 May 2011 23:20:46 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=domainkey-signature:mime-version:in-reply-to:references:date
:message-id:subject:from:to:content-type;
bh=pxyVZCcGdSVeT0v+uiN292vAV8VJHCzK5kADCyUqEH8=;
b=p9LxqV/90dmFLGFPJg7ToDJLVC2GUhW/iWzQHN8+AdD9O1yv6mndDYipkGWoSle4tG
pYyeYlOhS0HyUUtF1636MCxcLMeb2JJ3MbdDeZqVg8j5qQmQIHVPDs1ayZOsDkki9Dk8
U6mPRhY5S07jy3obc5nVg3c5ZLTEqA0d9ka0A=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=gmail.com; s=gamma;
h=mime-version:in-reply-to:references:date:message-id:subject:from:to
:content-type;
b=Eg7Qm2cfEYp6SpUjuZpt0A5ggo2N9itZRpkhf2LFNsY73E3qs5af95eeme1ybHDI2+
tASfqM6HZpUUm0BITehKk0xSd/fXOH6YZfDdQI5rTB/uQNmGsmcWu/+gphcapAtE8xkZ
1p5aIj1XSa6+zyy9fqw2KioWQPkS6cV/aT26I=
MIME-Version: 1.0
Received: by 10.216.235.234 with SMTP id u84mr2134162weq.51.1306736446461;
Sun, 29 May 2011 23:20:46 -0700 (PDT)
Received: by 10.216.72.144 with HTTP; Sun, 29 May 2011 23:20:46 -0700 (PDT)
In-Reply-To: <bffa3f39-4256-4f92-942c-ec607b929...@p6g2000vbn.googlegroups.com>
References: <21493300.3026.1305224420038.JavaMail.geo-discussion-forums@yqfv25>
<bffa3f39-4256-4f92-942c-ec607b929...@p6g2000vbn.googlegroups.com>
Date: Mon, 30 May 2011 00:20:46 -0600
Message-ID: <BANLkTikCK7k9S-pH+OCdEUMAnimzo_f...@mail.gmail.com>
Subject: Re: [symfony-users] Re: Highlighting menu based on controller called
From: oscar balladares <liebegr...@gmail.com>
To: symfony-users@googlegroups.com
Content-Type: multipart/alternative; boundary=000e0cd5153ab4d5aa04a47849fd
--000e0cd5153ab4d5aa04a47849fd
Content-Type: text/plain; charset=ISO-8859-1
What I'm doing is to get the actual route in template, and if a route matchs
a category (lets say),
then print an "id='current'"
for example:
<li><a
{% if app.request.attributes.get('_route') == 'homepage' %}
class='current'
{% endif %}
href="{{ path('homepage') }}">Home</a></li>
That's it. Of course it will become clumsy when you have many links cause it
is hard to read through.
I'll go with MenuBundle in my next project update schedule.
2011/5/28 FuzzyBird <nicolas.worm...@gmail.com>
> I think a good way to do it is, in the controller :
>
> // first generate the menu structure
>
> // you may want to do the following in a loop for all your menu items
> if ($this->get('router')->generate('some-route') === $this-
> >get('request')->getRequestUri() ){
> // highlight the link of this route
> }
>
> Hope it helped
>
> On May 12, 8:20 pm, Filipe La Ruina <filaru...@gmail.com> wrote:
> > Hey guys,
> > I've been searching for a way of getting the controller that was called
> so I
> > can highlight the menu.
> > I looked in the HTTP Foundation class and it seems that there is no way
> of
> > doing it.
> > Even searching here I couldn't find anyone that had the same problem.
> > Well, now i'm doing it the following way (note that I need it to show
> some
> > element in the html and a class in an element)
> >
> > <ul class="menu">
> > <li {% if (app.request.getPathInfo == '/foo')
> > %}class="selected"{% endif %}>
> > {% if (app.request.getPathInfo == '/foo') %}
> > <span class="border left"></span>
> > {% endif %}
> > <a href="{{ url('foo') }}">Foo</a>
> > {% if (app.request.getPathInfo == '/foo') %}
> > <span class="border right"></span>
> > {% endif %}
> > </li>
> > <li {% if (app.request.getPathInfo == '/bar')
> > %}class="selected"{% endif %}>
> > {% if (app.request.getPathInfo == '/bar') %}
> > <span class="border left"></span>
> > {% endif %}
> > <a href="{{ url('bar') }}">Bar</a>
> > {% if (app.request.getPathInfo == '/bar') %}
> > <span class="border right"></span>
> > {% endif %}
> > </li>
> > </ul>
> >
> > For now it is working since I don't have /foo/abc for example, all the
> urls
> > are /foo and /bar so the test will work.
> > Also I think that is not a nice way of testing (actually using the url
> and
> > not the controller name)
> > So is there anyway of getting the controller name on the template?
>
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony users" group.
> To post to this group, send email to symfony-users@googlegroups.com
> To unsubscribe from this group, send email to
> symfony-users+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/symfony-users?hl=en
>
--000e0cd5153ab4d5aa04a47849fd
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
What I'm doing is to get the actual route in template, and if a route m=
atchs a category (lets say),<div>then print an "id=3D'current'=
"</div><div><br></div><div>for example:</div><div><br></div><div><div>
<li><a</div><div>=A0=A0 =A0 =A0 =A0<span class=3D"Apple-tab-span" =
style=3D"white-space:pre"> </span>{% if app.request.attributes.get('_ro=
ute') =3D=3D 'homepage' =A0%}</div><div>=A0=A0 =A0 =A0 =A0<span=
class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>class=3D'cu=
rrent'</div>
<div>=A0=A0 =A0 =A0 =A0<span class=3D"Apple-tab-span" style=3D"white-space:=
pre"> </span>{% endif %}</div><div>=A0=A0 =A0 =A0=A0href=3D"{{ path(&#=
39;homepage') }}">Home</a></li></div><div><br></div=
><div>That's it. Of course it will become clumsy when you have many lin=
ks cause it is hard to read through.</div>
<div>I'll go with MenuBundle in my next project update schedule.</div><=
br><div class=3D"gmail_quote">2011/5/28 FuzzyBird <span dir=3D"ltr"><<a =
href=3D"mailto:nicolas.worm...@gmail.com">nicolas.worm...@gmail.com</a>>=
</span><br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex;">I think a good way to do it is, in the cont=
roller :<br>
<br>
// first generate the menu structure<br>
<br>
=A0// you may want to do the following in a loop for all your menu items<br=
>
if ($this->get('router')->generate('some-route') =3D=
=3D=3D $this-<br>
>get('request')->getRequestUri() ){<br>
=A0 =A0 =A0// highlight the link of this route<br>
}<br>
<br>
Hope it helped<br>
<div><div></div><div class=3D"h5"><br>
On May 12, 8:20=A0pm, Filipe La Ruina <<a href=3D"mailto:filaru...@gmail=
.com">filaru...@gmail.com</a>> wrote:<br>
> Hey guys,<br>
> I've been searching for a way of getting the controller that was c=
alled so I<br>
> can highlight the menu.<br>
> I looked in the HTTP Foundation class and it seems that there is no wa=
y of<br>
> doing it.<br>
> Even searching here I couldn't find anyone that had the same probl=
em.<br>
> Well, now i'm doing it the following way (note that I need it to s=
how some<br>
> element in the html and a class in an element)<br>
><br>
> <ul class=3D"menu"><br>
> =A0 =A0 =A0 =A0 =A0 =A0 <li {% if (app.request.getPathInfo =A0=3D=
=3D '/foo')<br>
> %}class=3D"selected"{% endif %}><br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {% if (app.request.getPathInfo =A0=3D=
=3D '/foo') %}<br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <span class=3D"border left&quo=
t;></span><br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {% endif %}<br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <a href=3D"{{ url('foo'=
;) }}">Foo</a><br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {% if (app.request.getPathInfo =A0=3D=
=3D '/foo') %}<br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <span class=3D"border right&qu=
ot;></span><br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {% endif %}<br>
> =A0 =A0 =A0 =A0 =A0 =A0 </li><br>
> =A0 =A0 =A0 =A0 =A0 =A0 <li {% if (app.request.getPathInfo =A0=3D=
=3D '/bar')<br>
> %}class=3D"selected"{% endif %}><br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {% if (app.request.getPathInfo =A0=3D=
=3D '/bar') %}<br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <span class=3D"border left&quo=
t;></span><br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {% endif %}<br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <a href=3D"{{ url('bar'=
;) }}">Bar</a><br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {% if (app.request.getPathInfo =A0=3D=
=3D '/bar') %}<br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <span class=3D"border right&qu=
ot;></span><br>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {% endif %}<br>
> =A0 =A0 =A0 =A0 =A0 =A0 </li><br>
> </ul><br>
><br>
> For now it is working since I don't have /foo/abc for example, all=
the urls<br>
> are /foo and /bar so the test will work.<br>
> Also I think that is not a nice way of testing (actually using the url=
and<br>
> not the controller name)<br>
> So is there anyway of getting the controller name on the template?<br>
<br>
--<br>
If you want to report a vulnerability issue on symfony, please send it to s=
ecurity at <a href=3D"http://symfony-project.com" target=3D"_blank">symfony=
-project.com</a><br>
<br>
You received this message because you are subscribed to the Google<br>
Groups "symfony users" group.<br>
To post to this group, send email to <a href=3D"mailto:symfony-users@google=
groups.com">symfony-users@googlegroups.com</a><br>
To unsubscribe from this group, send email to<br>
<a href=3D"mailto:symfony-users%2Bunsubscribe@googlegroups.com">symfony-use=
rs+unsubscribe@googlegroups.com</a><br>
For more options, visit this group at<br>
<a href=3D"http://groups.google.com/group/symfony-users?hl=3Den" target=3D"=
_blank">http://groups.google.com/group/symfony-users?hl=3Den</a><br>
</div></div></blockquote></div><br></div>
--000e0cd5153ab4d5aa04a47849fd--