【问题标题】:Inline HAML Links but with content内联 HAML 链接,但包含内容
【发布时间】:2012-06-10 22:48:25
【问题描述】:

我正在尝试输出一些类似的东西

<p>Hello, this is my text. <a href="#">Link here</a> This is more text</p>

但使用 HAML

如何做到这一点?我一直在寻找示例,但没有一个示例显示如何做到这一点,而是在链接的任一侧使用纯文本?

尼尔

【问题讨论】:

    标签: ruby-on-rails views haml


    【解决方案1】:

    如果你想做一个 1 班轮:

    %p= "Hello, this is my text. #{link_to 'Link here', '#'} This is more text".html_safe
    

    多行

    %p 
      Hello, this is my text. 
      = link_to 'Link here', '#'
      This is more text
    

    【讨论】:

    • 刚试过这个:%p= "This is my text #{ link_to "See ALL albums", albums_path }" 但那只是输出 This is my text See所有专辑我将如何解决这个问题?
    • 将 html_safe 添加到末尾(在答案中更改)
    • %p= "这是我的文字#{ link_to "查看所有专辑", albums_path }".html_safe
    【解决方案2】:

    你应该能够做到这一点:

    %p Hello, this is my text. <a href="#">Link here</a> This is more text
    

    这也可以:

    %p
      Hello, this is my test.
      %a{:href => '#'} Link here
      This is more text
    

    【讨论】:

      猜你喜欢
      • 2012-04-02
      • 2014-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-14
      • 1970-01-01
      • 1970-01-01
      • 2014-06-30
      相关资源
      最近更新 更多