开发者

Using the Coldbox framework, is there a way to intercept a renderView call and execute a different template?

I am trying to learn Coldbox to perhaps replace the current framework I am using. One of the features that I currently use is the ability to override any of the template inclusions by convention.

Essentially, lets say I have a view, "views/home.cfm"

<h1>I am the default theme</h1>

and that is all well and good. But lets say that I have a different view, "themes/[theme-name]/views/home.cfm"

<h1>I am the user chosen theme</h1>

that I want to include cond开发者_JS百科itionally (say there is a cookie to determine what theme is in use). Also, if the file does not exist, the default/fallback view should be rendered.

Is there any way of doing this overriding the system functions?

I looked at interceptors, and the preViewRender and postViewRender interceptors seem like the place to do something like this, but there doesn't seem to be any way of manipulating the actual workflow. If seems to be mainly pre/post processing of the content. For instance, there doesn't seem to be a way to "return false" to tell the renderView method to not actually render the view. Or any way to affect the location in which the view is to be found.

Any ideas?


Tyler,

The ColdBox Framework is quite flexible. It is possible to do what you desire but I don't think modifying renderView() is the best way to resolve this--although, you most definitely can.

I would encourage you to create a User Defined Function in the /includes/helpers/ApplicationHelper.cfm file that contains the logic you require. The functions that are added to this helper file are accessible from anywhere in the framework. This would allow you to create a function called "renderSkin()" that contains the logic you need. RenderSkin() would ultimitly call "renderView()" when you finally figured out which template you wanted to render for that user.

Respectfully,

Aaron Greenlee


I would suggest you go with the interceptor route, but change the layout instead of the view.

From the postEvent interceptor you can get the processedEvent key from the interceptData to change the layout.

Otherwise you could just make the check part of the layout page. The layout can the be a switch statement (or a more OO approach) $including the themed layout files as needed. This has the advantage of giving you a chance to emit custom interception points and having common functionality (css, js)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜