How do I yield contentFor?

42 views
Skip to first unread message

bryan rasmussen

unread,
Jul 9, 2014, 1:10:08 PM7/9/14
to compo...@googlegroups.com

Hi,

I was thinking that if I had a contentFor inside of my application layout, such as

<%- contentFor('javascripts') %>

Then I should be able to yield content to it from within a template, with a syntax that might look something like this


<%- yieldContent('javascripts'){ %>

 stuff I want to show up in the javascripts area is handled here...
<%- } %>


The documentation on contentFor is however somewhat unclear as to how you yield content to it?

Thanks

Anatoliy Chakkaev

unread,
Jul 9, 2014, 1:37:44 PM7/9/14
to compo...@googlegroups.com
Unfortunately you can not yield like that. At the moment you can only add something to section by passing is as second param of 'contentFor' method.


--
The official community of CompoundJS.
 
website: compoundjs.com
source: https://github.com/1602/compound
bug reports: https://github.com/1602/compound/issues?state=open
---
You received this message because you are subscribed to the Google Groups "CompoundJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to compoundjs+...@googlegroups.com.
To post to this group, send email to compo...@googlegroups.com.
Visit this group at http://groups.google.com/group/compoundjs.
For more options, visit https://groups.google.com/d/optout.

bryan rasmussen

unread,
Jul 10, 2014, 3:12:13 AM7/10/14
to compo...@googlegroups.com, ma...@anatoliy.in
sorry, but I'm not understanding how it works.

I better describe the scenario completely - I'm taking over someone elses compoundjs application. They had a bunch of inline javascript inside of particular views, I want to load these at the bottom of the page.

views are loaded inside of application layout.

I need to be able to know what scripts to load based on what view I am actually rendering, but also because I don't want to spend a lot of time rewriting this extremely spaghetti like part of the application right now I need to just be able to say have these inline scripts loaded at the end of my page where they won't block.

So if I have a contentFor("endofpage"); at the end of my application layout, how do I make add stuff to that area?

Can it be done in this way? Or is there another 'proper way' that compoundjs does it? I mean I can hack my way around it in lots of different way, I was just wondering if there was a specific way I should do this?

Thanks,
Bryan Rasmussen

Anatoliy Chakkaev

unread,
Jul 10, 2014, 4:04:25 AM7/10/14
to compo...@googlegroups.com
I understand what are you trying to do, but in ejs you can not pass block to contentFor. Maybe it is possible now, but it was not possible when it was implemented. So, the only way to render string "smth" in application layout's footer is to call <% contentFor('footer', 'smth') %> in view. Or, maybe you can make it working with block as you described.

bryan rasmussen

unread,
Jul 10, 2014, 2:29:22 PM7/10/14
to compo...@googlegroups.com, ma...@anatoliy.in
Ok, I was thinking it might be possible to do something like this
https://www.npmjs.org/package/express-ejs-layouts in Compoundjs as it already works..

Thanks,
Bryan Rasmussen
Reply all
Reply to author
Forward
0 new messages