Problem
I have a partial, which contains HTML structure for repeating elements of FAQ entry.
partials/_faqitem.haml
:
.question
%a.faq-toggle{"data-toggle" => "collapse", :href => "\##{item}"}
= data.faq[item].q
%div{:class => "collapse", :id => "#{item}"}
Text directly in partial
I am using it in my faq.html.md.erb.haml
template:
= partial(:"partials/faqitem", :locals => { :item => "mm" })
This properly renders HTML and inserts data from data/faq.yaml
:
mm:
q: What is Middleman?
info: Some other info
The problem arises when I try to add more text back in my template, under = partial
call. I can’t nail proper indentation that would allow me to render text in template inside div
tag, in the same way as “Text directly in partial” is rendered.
Example of nesting in the template:
= partial(:"partials/faqitem", :locals => { :item => "mm" })
Text in the template
= partial(:"partials/faqitem", :locals => { :item => "mm" })
Text in the template
Depending on the level of nesting, I get either one of these errors:
syntax error, unexpected keyword_end, expecting end-of-input y in partial\n", 0, false);end;_hamlout.buffer << _hamlout.f ^
or
The line was indented 2 levels deeper than the previous line.
Is there any way to add text directly in the template in a way that will be rendered in the same way as if it would be nested inside tag from the partial?
Specific example
To better illustrate desired result, here is an example.
faq.html.md.erb.haml
template:
= partial(:"partials/faqitem", :locals => { :item => "mm" })
This is some text in the template.
:markdown
Now a little markdown to complicate things and then I will insert some information from data file, because I don't want to repeat myself.
= data.faq.mm.info
This, used with partials/_faqitem.haml
:
.question
%a.faq-toggle{"data-toggle" => "collapse", :href => "\##{item}"}
= spanmarkdown(data.faq[item].q)
%div{:class => "collapse", :id => "#{item}"
Should produce the same result as if the content from template was placed directly inside partial:
.question
%a.faq-toggle{"data-toggle" => "collapse", :href => "\##{item}"}
= spanmarkdown(data.faq[item].q)
%div{:class => "collapse", :id => "#{item}"}
This is some text in the template.
:markdown
Now a little markdown to complicate things and then I will insert some information from data file, because I don't want to repeat myself.
= data.faq.mm.info