put haml tags inside link_to helper

后端 未结 3 1706
故里飘歌
故里飘歌 2020-12-13 17:42

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/t         


        
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 17:48

    The simplest way to do it is by using html_safe or raw functions

    = link_to 'Other Page'.html_safe, "path/to/page.html"
    

    or using raw function (recommended)

    = link_to raw('Other Page'), "path/to/page.html"
    

    Simple as it can get !!

    Don’t use html_safe method unless you’re sure your string isn’t nil. Instead use the raw() method, which wont raise an exception on nil.

提交回复
热议问题