collection option in .partial

66 views
Skip to first unread message

Oleg Slobodskoi

unread,
Apr 11, 2011, 2:22:05 PM4/11/11
to Express
hi,

I am reading renderPartial private method from view.js and don't get
how it supposed to work.

if I pass array as second argument partial('view', [{a:1}, {a:2}]) it
should render the partial "view" 2 times and pass first and second
array element.

your jade example seems to work so, but in my implementation I am not
getting array elements, instead the whole res thing and the only place
I can see needed array elements is res.view.

Need help :)

https://github.com/kof/node-jqtpl

Oleg

TJ Holowaychuk

unread,
Apr 11, 2011, 2:23:45 PM4/11/11
to expre...@googlegroups.com
yeah with a collection all it does is iterate and keep calling render()

-- 
TJ Holowaychuk
--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.

Oleg Slobodskoi

unread,
Apr 11, 2011, 2:25:01 PM4/11/11
to expre...@googlegroups.com
so the only way to access elements is res.view (my example)?

2011/4/11 TJ Holowaychuk <tjholo...@gmail.com>:

--
regards,
Oleg Slobodskoi
--------------------------------------------------------------------
Xing: https://xing.com/profile/Oleg_Slobodskoi
Twitter: https://twitter.com/oleg008
Github: https://github.com/kof

TJ Holowaychuk

unread,
Apr 11, 2011, 2:26:30 PM4/11/11
to expre...@googlegroups.com
res.partial('pet', ['tobi', 'loki']) would render the template twice with the "pet" local var first set to "tobi", then "loki"

-- 
TJ Holowaychuk

Oleg Slobodskoi

unread,
Apr 11, 2011, 2:28:50 PM4/11/11
to Express
but how the partial view should know its name. you are using a fancy
method to resolve the key from view path: partial.resolveObjectName.


On Apr 11, 8:26 pm, TJ Holowaychuk <tjholoway...@gmail.com> wrote:
> res.partial('pet', ['tobi', 'loki']) would render the template twice with the "pet" local var first set to "tobi", then "loki"
>
> --
> TJ Holowaychuk
>
>
>
>
>
>
>
> On Monday, April 11, 2011 at 11:25 AM, Oleg Slobodskoi wrote:
> > so the only way to access elements is res.view (my example)?
>
> > 2011/4/11 TJ Holowaychuk <tjholoway...@gmail.com>:

TJ Holowaychuk

unread,
Apr 11, 2011, 2:31:24 PM4/11/11
to expre...@googlegroups.com
you can use the "as" option, by default it resolves the name, why do you need to know the name dynamically? 

-- 
TJ Holowaychuk

Oleg Slobodskoi

unread,
Apr 11, 2011, 2:37:14 PM4/11/11
to Express
lets take an example:

//main.html
<div id="main">{{partial('partial.html'), [{a:1}, {a:2}] }}</div>

//partial.html
<div id="partial">${a}</div>

// expected output
<div id="main">
<div id="partial">1</div>
<div id="partial">2</div>
</div>


this is how I expect it to work ... but it seems I mistunderstand
something ...

Oleg Slobodskoi

unread,
Apr 11, 2011, 2:38:29 PM4/11/11
to Express
ups little mistake


//main.html
<div id="main">{{partial( [{a:1}, {a:2}]), 'partial.html'}}</div>
//partial.html
<div id="partial">${a}</div>
// expected output
<div id="main">
<div id="partial">1</div>
<div id="partial">2</div>
</div>

TJ Holowaychuk

unread,
Apr 11, 2011, 2:41:45 PM4/11/11
to expre...@googlegroups.com
no, the object keys are not expanded as locals, those two objects become "the" object passed. so partial.a would be 1 the first time, 2 the second time

-- 
TJ Holowaychuk

Oleg Slobodskoi

unread,
Apr 11, 2011, 2:43:52 PM4/11/11
to Express
and this means I would have to know the name of my partial to access
the data ... so "partial.a" ... this is not hard in this example, but
considering what the fancy method "partial.resolveObjectName" can
do ... I actually can't access it just directly ...

TJ Holowaychuk

unread,
Apr 11, 2011, 2:46:15 PM4/11/11
to expre...@googlegroups.com
partial('something', { as: 'user', collection: [user, user2, user3] })

or

partial('user', [user, user2, user3])

usually best just to not name things poorly, but it can be done with the options, it's just much more  verbose.

-- 
TJ Holowaychuk

TJ Holowaychuk

unread,
Apr 11, 2011, 2:47:47 PM4/11/11
to expre...@googlegroups.com
if you want to key them, just iterate yourself and use res.partial('foo', { a: 'something' }), explicitly passing the locals

-- 
TJ Holowaychuk

Oleg Slobodskoi

unread,
Apr 11, 2011, 2:49:36 PM4/11/11
to Express
so I have explicitely name the key the data will be attached to.

I suppose its because partials have parent data as a root key:value
and you are trying to separate them?

TJ Holowaychuk

unread,
Apr 11, 2011, 2:52:16 PM4/11/11
to expre...@googlegroups.com
partials are primarily focused to a single object, which is how we can cut down on the verbosity a bit by assuming things. if you just simply want to render a template, use res.render() with layout: false if needed

-- 
TJ Holowaychuk

Oleg Slobodskoi

unread,
Apr 11, 2011, 2:53:46 PM4/11/11
to Express
ok, I just saw into documentation, this ".as" thing is not in.

TJ Holowaychuk

unread,
Apr 11, 2011, 2:54:45 PM4/11/11
to expre...@googlegroups.com

Oleg Slobodskoi

unread,
Apr 11, 2011, 3:01:04 PM4/11/11
to Express
Reply all
Reply to author
Forward
0 new messages