Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

put haml tags inside link_to helper

is it possible to add html-content inside a link_to helper in HAML?

i tried this, but all i get is a syntax error:

= link_to "Other page", "path/to/page.html"     %span.icon Arrow 

expected output:

<a href="path/to/page.html">Other Page<span class="icon">Arrow</span></a> 
like image 437
flavaflo Avatar asked Mar 08 '12 14:03

flavaflo


2 Answers

You should use block

= link_to "path/to/page.html" do   Other page   %span.icon Arrow 
like image 160
Michał Szajbe Avatar answered Sep 23 '22 08:09

Michał Szajbe


If anyone is still using Rails 2.x on a project, it looks like the accepted answer returns the block, thus duplicating the link in the markup. Very simple change: use - instead of =

- link_to "path/to/page.html" do   Other page   %span.icon Arrow 
like image 32
Paul Avatar answered Sep 24 '22 08:09

Paul