RE: [coldbox:16974] [coldbox 3.5.3] multiple renderView()

Am I understanding correctly the the view name referenced in that example is static? So if I have a layout with renderView(‘someview’) I’m literally getting a view named someview.cfm?

Yes, that is correct.

As an example of what I’m looking for let’s say I have a 3-piece layout template. It has a top nav, a left section and top nav however would have to be a static reference, a var of passed in prebuilt html, or some sort of “mini-event” per your previous example (which I obviously don’t quite understand yet).

Those are 3 valid options, but you can also set dynamic view names in your handler it’s really up to you. You have the power to create a layout that is as dynamic is you want it to be, and you can choose what data you feel like passing from the handler to the layout to help control the output of the page.

What I was hoping is my handler could…

setView(1,‘someview’)
setView(2,‘someview’)

setView(3,‘someview’)

and layout could…

renderView(1)
renderView(2)

renderView(3)

ColdBox doesn’t not support that specific syntax. We assume that the vast majority of events will render a single view inside of a layout. What you are demonstrating is absolute possible though:

In your handler:
rc.view1 = ‘assets/view1’;
rc.view2 = ‘assets/view2’;
rc.view3 = ‘assets/view3’;

And in the layout:

#renderView(rc.view1)#
#renderView(rc.view2)#
#renderView(rc.view3)#

I don’t quite understand why you’d want every page in your site to specify a different left, top, and right nav instead of using a consistent layout, but I guess you can do whatever you need.

As far as the difference between running an event and rendering a view, the only difference is that the event your running has a chance to gather any data needed for it’s view before rendering it. I already spelled out the code for it below (did you try it?) That example would look like this:

In your handler:
rc.event1 = ‘myHandler.event1’;
rc.event2 = ‘myHandler.event2’;
rc.event3 = ‘myHandler.event3’;

And in another supporting handler:
myHandler.cfc

function event1(event,rc,prc) {
local.dataForView1 = service.getData();
return renderView(“view1”, args=local.dataForView1);

}

function event2(event,rc,prc) {
local.dataForView2 = service.getData();
return renderView(“view3”, args=local.dataForView2);
}

function event3(event,rc,prc) {
local.dataForView3 = service.getData();
return renderView(“view3”, args=local.dataForView3);
}

And in your layout:

#runEvent(rc.event1)#
#runEvent(rc.event2)#
#runEvent(rc.event3)#

There’s no magic really, it’s just ColdBox events return HTML from a view that they’ve rendered.

It just seems a lot simpler than treating one view as “setView” and any others in a static or custom fashion.

It may seem simpler to you, but most people only deal with one view per event, so that’s the use case that we made easiest.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

The example of rc.view1 = ‘assets/view1’; is exactly what I was looking for. Thanks!

The whole idea behind the different views is just that I’m using the layout as a master template (using either Blueprint or Twitter Bootstrap) and dropping in different pieces into the those three areas mentioned based on viewer rights (Human Resources vs Financial Officer for instance), current event they’re looking at, etc. That way I usually end up with no more than 3 or 4 layout templates that can be filled in a variety of ways and provide a uniform look. Anyway, the example you provided is perfect. Thanks again!