0

Is it possible to use content_for in *.xml.builder files?

when I print:

content_for :part do 
  xml.child "anything"
end

xml.parent do 
  xml << yield(:part) if content_for? :part
end

it returns

<child>anything</child> <parent> <child>anything</child> </parent>

But I need only

<parent> <child>anything</child> </parent>

gayavat
  • 18,910
  • 11
  • 45
  • 55
  • 1
    I am not familiar with xml builder so bear with me, but looking at the code it seems like `content_for` generates a `anything` node but already appends it to your `` element. Since you do an additional `xml << yield(:part)` it probably appends it again, but then at the root. What happens if you just do `yield(:part)`, i.e., without the `xml <<` part? – Daniël Knippers Aug 15 '14 at 08:55
  • probably it was fixed anytime ago. as content_for does not return anything now – gayavat May 15 '15 at 07:06
  • no. I hop to it, it is a still problem. If just yield(:part) is called, there is no content in parent block – gayavat May 15 '15 at 07:09

0 Answers0