开发者

How do I put a link in the middle of a paragraph with HAML?

How do I cre开发者_StackOverflowate this:

<p>
  I would like to make a <a href="foo.html">link</a> in my Rails app.
</p>

with HAML?


1.

%p
  I would like to make a
  %a
    link
  in my Rails app.

2.

%p
  I would like to make a <a href="#">link</a> in my Rails app.


The "pure" HAML way:

%p
  I would like to make a 
  %a{:href => "foo.html"} link
  in my Rails app.

Using the Rails link_to helper:

%p
  I would like to make a 
  =link_to "link", "foo.html"
  in my Rails app.


I recommend reading Chris Eppstein's post "Haml Sucks for Content", and using something like Markdown or Textile to handle inline markup. I'm a big fan of Haml for document structure and a simple link in a paragraph is simple enough, but Haml starts to get out of control pretty fast.


If you know your routes, then you can do this:

%p
  I would like to make a #{link_to "link", foo_path} in my Rails app.

Pretty simple. Just wrap your Ruby syntax with #{}.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜