Nico Ritsche
2007-Oct-26 22:41 UTC
[Masterview-users] conditional styling of html elements whithout element duplication
Hi,
first of all I think MasterView is a very useful tool. Good work!
I''m struggling to get the following working: I have a menu consisting
of several links. Dependent on the current controller action, the according
menu link should be styled differently than the other links.
My current solution is to do this for each menu option:
<li><a mv:if="@current_page == ''home''"
href="home.html" mv:link_to=":action
=> ''index''"><strong
class="selected">Home</strong></a>
<a mv:else="" href="home.html" mv:link_to=":action
=> ''index''">Home</a></li>
..
..
However, this doesn''t work very nicely, as the static html shows each
menu
option twice.
Also it seems a bit awkward. Another idea I had is to use something like
this:
<li mv:attr=":class => #{ if @selected == ''home''
''selected'' else
''not_selected'' end }"> <a href="new.html"
mv:link_to=":action =>
''index''">Home</a></li>
This doesn''t compile as the erb #{ if @selected ==
''home'' ''selected'' else
''not_selected'' end } isn''t correct,
I could use erb directly I guess, like this
{{{ if @selected == ''home'' }}}
<li class="selected" >...</li>
{{{ else }}}
<li class="not-selected" >...</li>
{{{ end }}}
But than I have the double links again.
Is there a good way of achieving what I want? Conditional styling of page
elements while keeping only one alternative in the static html
seems quite an essential thing to me. Anyway, I''m new to rails and
MasterView, so I might have overlooked some more obvious solution.
Nico
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://rubyforge.org/pipermail/masterview-users/attachments/20071026/8fd0cf5d/attachment.html