Rails: Arbre yield content for
Appearance
Problem
Within Arbre, the normal yield :foo doesn't display output captured like:
content_for :foo do
span 'bar'
endInstead, wrongly, span 'bar' is output immediately within the Arbre template, and yield :foo renders nothing.
Environment
- rails-7
Solution
Within content_for, wrap the output in Arbre::Context and convert to string (to_s):
content_for :foo do
Arbre::Context.new do
span 'bar'
end.to_s
endNow within an Arbre template, use text_node or content_for to output the captured content:
text_node yield(:foo)
text_node content_for(:foo) # Alternative notation