How to render HTML inside Slim templates

你离开我真会死。 提交于 2019-12-03 10:45:59

You want to disable HTML escaping for the link_to argument, not the entire link_to result. You're pretty close with your html_safe but your string interpolation is eating your "safe for HTML" flag. This should work better:

li= link_to '<i class="icon-user"></i> My Profile'.html_safe, current_user

This has been answered, but if you actually have some html and you want to render it in a slim template, use double equal.

== "<i>test</i>"

Will be the same as

= "<i>test</i>".html_safe

Alternatively, you could write this as

li
  a href=url_for(current_user)
    i.icon-user My Profile

which arguably is a little easier to read.

There's another way of tackling this below in case it helps anyone. Using a block is especially useful if you have more complex code to include within the link.

li
  = link_to current_user do
    i.icon-user>
    | My Profile
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!