inline tag in haml

前端 未结 5 2051
余生分开走
余生分开走 2021-01-31 15:31

In html, you can do something like this

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eget aliquet odio. Fusce id quam eu augu

5条回答
  •  别跟我提以往
    2021-01-31 16:19

    As a hybrid of these nice answers by others, I think you can define a Helper method in your application_helper.rb for some inline markups you'd frequently use. You don't need to mix HTML with HAML, nor do you have to type much.

    In your helper;

    def em(text)
      content_tag(:em, text)
    end
    
    #def em(text)
    #  "#{text}".html_safe
    #end
    

    In your haml;

    %p
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eget 
        aliquet odio. Fusce id quam eu augue sollicitudin imperdiet eu ac eros. 
        #{em 'Etiam nec nisi lorem'}, ac venenatis ipsum. In sollicitudin, 
        lectus eget varius tincidunt, felis sapien porta eros, non 
        pellentesque dui quam vitae tellus. 
    

提交回复
热议问题