Using partials with Jade

342 views
Skip to first unread message

Narciso Jaramillo

unread,
May 31, 2012, 3:46:30 AM5/31/12
to doc...@googlegroups.com
Hi,

Just started playing with DocPad--looks very cool!--and am trying to build a simple blog using Jade. You can see my repo at http://github.com/njx/njx.github.com (ignore the files at the top level).

I'm having a problem with my partial() call in documents/index.html.jade. The partial (partials/post.html.jade) seems to get the document title and date properly, but for the content it doesn't actually render the document's content using jade--it just dumps the raw jade source in.

I'm not super familiar with Jade and don't fully understand the DocPad architecture, so any guidance would be helpful :) Thanks!

nj

Narciso Jaramillo

unread,
May 31, 2012, 4:05:32 AM5/31/12
to doc...@googlegroups.com
(BTW, I realize that my structure is kind of messed up right now--the post document should also have a standalone layout to let it be rendered as its own page, and only some fragment of it should be included in the index.html. But I'd like to figure out how to render that fragment properly within the index.html page.)

divya manian

unread,
May 31, 2012, 11:04:18 AM5/31/12
to doc...@googlegroups.com
I think the partials need to be Jade (partial.jade rather than
partial.html.jade)? Because index.html.jade expects its content to be
Jade?
> --
> You received this message because you are subscribed to the Google Groups
> "DocPad" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/docpad/-/1BLR08m4ukoJ.
>
> To post to this group, send email to doc...@googlegroups.com.
> To unsubscribe from this group, send email to
> docpad+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/docpad?hl=en.

Narciso Jaramillo

unread,
May 31, 2012, 4:00:14 PM5/31/12
to doc...@googlegroups.com
Hmm, that didn't work. Actually, I think the problem is the other way around. My partial, post.html.jade, is indeed getting processed by Jade into HTML, and then index.html.jade is taking that HTML and interpolating it directly into the output, which is correct. Within the partial, the h1= and time= are getting correctly processed by Jade into HTML as well. But then I need to include the content of the document, so I'm doing !{content}...but the content is jade, not HTML, so needs to be actually interpreted. I had assumed since the content itself is a .html.jade document, it would get processed into HTML before being included in the partial, but that doesn't seem to be happening.

I feel like there must be some other more correct way to do what I'm trying to do in DocPad...

nj
> docpad+unsubscribe@googlegroups.com.

Benjamin Lupton

unread,
Jun 10, 2012, 6:49:22 AM6/10/12
to doc...@googlegroups.com
Looking at your source code, you have: !{partial("post.html.jade", document)} then inside your partial you have !{content}

Try changing !{content} to !{contentRendered}

Does that work? If so, I'll post the explanation later :)

Narciso Jaramillo

unread,
Jun 11, 2012, 4:21:04 PM6/11/12
to doc...@googlegroups.com
Thanks for the response. Unfortunately, changing it to contentRendered doesn't work--I get an error that contentRendered is not defined.

BTW, I'm using docpad@5.2, docpad-pl...@1.0.1, docpad-plug...@1.0.1. I tried switching over to 6.x and the 2.0 plugin versions, but ran into another problem there (it said "documents" was not defined in my "each document in documents" loop). Should I be using 6.x instead of 5.2?

nj

Narciso Jaramillo

unread,
Jun 24, 2012, 3:20:46 AM6/24/12
to doc...@googlegroups.com
Switched over to 6.0 (had to update my "documents" iterator to use getCollection()) and am still having the same problem--if I try to use !{content} in the partial I get the raw Jade, and if I try to use !{contentRendered} it says contentRendered is undefined. I've updated https://github.com/njx/njx.github.com with the current version.

nj

Narciso Jaramillo

unread,
Jun 24, 2012, 3:35:39 AM6/24/12
to doc...@googlegroups.com
Ah! I figured out a workaround, but it's kind of nasty. You can see it now in my github repo (linked below).

Basically, the issue is that the document wasn't being rendered when going through this codepath for some reason. So I had to grab the actual Backbone models from the collection and tell them to render before passing them into the partial. Once I did that, contentRendered became available.

Now I need to figure out how to make it so that the standalone post file renders with a different layout (that sets up a full HTML page), while the partial in the index page still renders without that layout.

nj

Benjamin Lupton

unread,
Jul 10, 2012, 7:45:17 PM7/10/12
to doc...@googlegroups.com
This should now be resolved with DocPad v6.1 as no longer clear the render status between passes - so you shouldn't have to do the workaround of calling render on the model manually.

Can someone confirm this is fixed?
Reply all
Reply to author
Forward
0 new messages