Including the contents of the variable inside the Haml filter

How to make article.content filtered: textiles?

  - @articles.each do |article| %article.post %header=article.name %p :textile =article.content %footer 

output

 <article class="post"> <header>game</header> <p> </p><p>=article.content</p> <p></p> <footer></footer> </article> 
+7
source share
2 answers

Inside the Haml filter, you use String interpolation to include Ruby code in your markup. For example:

 require 'haml' @x = 42 Haml::Engine.new("%p= @x").render(self) #=> "<p>42</p>\n" Haml::Engine.new(":textile\n\t= @x").render(self) #=> "<p>= @x</p>\n" Haml::Engine.new(":textile\n\t\#{@x}").render(self) #=> "<p>42</p>\n" @content = "alpha\n\n#hi **mom**" Haml::Engine.new(":textile\n\t\#{@content}").render(self) #=> "<p>alpha</p>\n<p>#hi <b>mom</b></p>\n" 

Change My previous answer was misleading regarding newlines in the content due to my erroneous testing. As you can see above, newlines in the included content are processed directly.

So your Haml template should look like this:

 - @articles.each do |article| %article.post %header=article.name :textile #{article.content} %footer 

Note that I removed the %p tag surrounding your markup, as Textile introduces its own paragraph wrappers (even for single-line content).

+7
source

Your syntax seems fine if everything else works out right, maybe it's a stone problem. Do you have RedCloth installed?

Edit: On the other hand, what is the second line doing? This may be the cause of your problem, since I don't think% article.post is the correct HAML syntax and there is a textile filter inside it.

+1
source

All Articles