简体   繁体   中英

Turn a div into a link in HAML using a Rails link_to tag, with nested content within

Sorry if this question doesn't make too much sense. I have a dropdown menu which expands. The first link in the menu that I want to expand on will be called "Overview". I want to use a link_to_function tag to expand the items below Overview. However, I want the first link to say "Overview +" all on one line, with the "+" later changing to a "-" once the menu has expanded. I also want the +/- to be justified right, and "Overview" to be justified left. I've already implements the +/- change.

How can I do something like the following? Haml won't allow me to nest the links like this. The +/- change has already been implemented, so that part is working.

#main.section= link_to_function 'Overview', "toggleMenu('#main')"
  %a +
  %a -

Basically, I want the overall div to be the actual link, while the nested %a tags within are just there for formatting purposes. Of course, I could easily use JavaScript to put a listener on #main, but I want this to be dynamic so that I can expand multiple sections of the menu the same way.

You can pass a do/end block to the link_to method:

= link_to home_path do
  %span= "Go to"
  %span= "Home!"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM