[Coldbox 5.4.0] renderView() not returning View data

When I call renderView() from my handler e.g.

`

<cfset prc.widgetView = renderView(view=“Widgets/getWidget”,args={widgetData=widgetData})>
`

I expected to see the HTML, CSS etc from my view being returned in prc.widgetView but instead it only returns the data in var widgetData. Is this a bug or am I missing something about how renderView works?

I just tested this and it works fine. What CF engine/version are you on? Can you share more code?

I created a stock ColdBox app in CommandBox with “coldbox create app” and created this file:

/views/main/foo.cfc

view output #args.brad#

And then I modified the index method of the main handler to have this line:

prc.welcomeMessage = renderView( view=‘main/foo’, args={ brad : ‘wood’ } );

And when I hit the home page of the site, the text

view output wood

shows on the screen, which is the output of my view.

I am basically trying to load a widget via an AJAX call which is calling the handler to get all the HTML, CSS, JS needed for the widget to function.

`
here is my call

`

and the handler

<cffunction name="getWidget"> <cfset var widgetData = WidgetsService.getWidgetData(widgetId)> <cfreturn renderView(view="Widgets/#widgetName#",args={widgetData=widgetData})> </cffunction>

I am on Lucee Lucee 5.3.3.4-SNAPSHOT.

If you just want HTML back, why are you returning renderview when you could just use a normal event.setView() and add nolayout if needed?

No matter, what do you get on the screen if you hit the ajax URL directly in a browser? If I change my test action to have this code, it works as expected and returns the HTML from my view to the browser:

return renderView( view=‘main/foo’, args={ brad : ‘wood’ } );

And to my point above, this is actually the way I’d recommend doing it, which works exactly the same.

event.setView(view=“main/foo”, noLayout=true, args={ brad : ‘wood’ });

That is what I ended up doing but I was trying to avoid having to put a blank layout. I was under the impression renderView would just get me the view on demand as detailed in the docs (https://coldbox.ortusbooks.com/the-basics/layouts-and-views/views/rendering-views).

I’ll go with the event.setView approach. Thanks for your help.

I still don’t understand what your original issue was. Also, I’m not sure what you mean by having a blank layout. Read my previous reply again and look at my code sample. All you need is noLayout=true and it skips the layout entirely.

Sorry should have been more precise. I tried noLayout=true but that also only returns just the data without the view elements. Had to use a blank layout for it to work.
I made a short video depicting the issue.
https://youtu.be/hBQMeNWUxu8

I’m not sure what you’re doing but that is not the behavior I get. There must be other things at play in your setup. You also didn’t show the actual code in your view nor the raw browser output of hitting the Ajax call directly.

Also on line 15 if your widget handler, you’re accessing widgetname directly out of the URL scope and not via rc. Also, it may not be safe to allow a user to pass their own view names since that variable ultimately ends up in a cfinclude call. That may be vulnerable to attacks that use …/…/…/ to include other files.

I figured out the issue.

In my viewHelper I had to wrap the my whole script in tag for it to render properly else it was only rendering the pieces of code that were wrapped inside the tag which in my case was the widgetData.

E.g.
`

`

I had to change to

`

`

Not sure why that is needed but I am glad it works now :slight_smile:

Thanks for your help and feedback as always.

That would be controlled by the enablecfoutputonly setting, though I’m not entirely sure why the behavior would change from one method to the other

Ah yes should have checked for that. I did have it turned on (carryover form a template I used) though to your point I am not sure why my other scripts that were not wrapped in were still working.