Help with rendering partials?

1,308 views
Skip to first unread message

Eric

unread,
Aug 1, 2013, 5:53:13 PM8/1/13
to ha...@googlegroups.com
Hello again,

Basically, I was wondering if it was possible to render partials in HAML, like with SASS's @import functionality for a local, static site.

The code is:

%h2 Footer Lorem Ipsum
= render :partial => "footer/_foo.haml"

 
With the file "_foo.haml" located in the folder footer. _foo.haml contains valid HAML (rendered properly, then cut and pasted out of the index and into the new partial document).

I'm using CodeKit to render my HAML, and receive one of the two error messages, depending on whether or not I indent with a tab:

undefined method `render' for #<Object:0x10c4ce1d8>

or

Illegal nesting: content can't be both given on the same line as %h2 and nested within it.

Is there something obvious I'm missing out on? And sorry if this reads weird. I've done a little searching on Google/Stack Exchange, I'm not a programmer by trade/don't know Ruby, and I'm a little shaky on the right terminology, so I'm not 100% if I'm phrasing the searches properly.

Duncan Beevers

unread,
Aug 1, 2013, 6:10:53 PM8/1/13
to ha...@googlegroups.com
The way you have that code indented, it looks like you're trying to render content into the %h2

I'm not sure what markup you're expecting, but with haml, indentation means inclusion.

Are you trying to render this?

<h2>Footer Lorem Ipsum<div>Content from footer/_foo.html</div></h2>
Or are you trying to render this?

<h2>Footer Lorem Ipsum</h2>
<div>Content from footer/_foo.html</div>

If you want the latter, simply un-indent your render call.

%h2 Footer Lorem Ipsum
= render :partial => "footer/_foo.haml"
Haml itself doesn't provide any mechanism for "partials"
When using Haml from within Rails, the render method call is handled by ActionView. I haven't used CodeKit before, but apparently it isn't providing this method for partial inclusion.

It looks like there's an old GitHub/haml-contrib thread about accessing this functionality in CodeKit (https://github.com/haml/haml-contrib/issues/1) so that might serve as a good jumping-off point for getting at the functionality you need.

Best,
Duncan



--
You received this message because you are subscribed to the Google Groups "Haml" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haml+uns...@googlegroups.com.
To post to this group, send email to ha...@googlegroups.com.
Visit this group at http://groups.google.com/group/haml.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Eric

unread,
Aug 2, 2013, 10:24:12 AM8/2/13
to ha...@googlegroups.com
That's a great starting off point, and the nesting comment totally makes sense in hindsight. Thanks for the help, I really appreciate it!
Reply all
Reply to author
Forward
0 new messages