Question

I have made a partial for generating some of the layout of my page, and I have in the partial a space where I would need to insert a description.

The description is static text from the caller of the partial, and it's pretty long. so I would like to write it as a block of text.

This is what I have:

= render "feature", title: "Planning", text: <<-BLOCK
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
BLOCK

but when I try rendering the page I get:

can't find string "BLOCK" anywhere before EOF
Was it helpful?

Solution

I would rather use a yield and provide the content in a content_for block.

In your partial:

%p Other content wrapping the block of text
= yield :text_block
%p Other content wrapping the block of text

Then in your view:

= content_for :text_block do
  The content you need to insert goes here ...

OTHER TIPS

This Rails code passes a "block"/heredoc to a partial within a HAML view:

- Haml::Template.options[:suppress_eval] = false
:ruby
  haml_io.puts render "feature", title: "Planning", text: <<BLOCK
  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  BLOCK

(using HAML 4.0.5 and Rails 3.2.13)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top