How to make article.content
filtered by :textile ?
- @articles.each do |article|
%article.post
%header=article.name
%p
:textile
=article.content
%footer
the output
<article class="post">
<header>game</header>
<p>
</p><p>=article.content</p>
<p></p>
<footer></footer>
</article>
Inside a 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"
Edit: My previous answer was misleading with respect to newlines in the content, due to my flawed testing. As seen above, newlines in included content are handled fine directly.
As such, your Haml template should simply look like this:
- @articles.each do |article|
%article.post
%header=article.name
:textile
#{article.content}
%footer
Note that I've removed your %p
tag surrounding your markup, as Textile introduces its own paragraph wrappers (even for single-line content).
Your syntax seems fine, if everything else is getting rendered properly maybe it's a gem issue. Do you have RedCloth installed?
Edit: On second thought, what does the second line do? It might be the cause of your problem since I don't think %article.post is proper HAML syntax and the :textile filter is inside it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With