View Events

All rendered views have associated events that are announced whenever the view is rendered via ColdBox Interceptors. These are great ways for you to be able to intercept when views are rendered and transform them, append to them, or even remove content from them in a completely decoupled approach. The way to listen for events in ColdBox is to write Interceptors, which are essential simple CFC's that by convention have a method that is the same name as the event they would like to listen to. Each event has the capability to receive a structure of information wich you can alter, append or remove from. Once you write these Interceptors you can either register them in your Configuration File or programmatically.

Event Data Description
preViewRender
  • view - The name of the view to render
  • cache - If the view will be cached
  • cacheTimeout - The cache timeout
  • cacheLastAccessTimeout - The idle timeout of the view
  • cacheSuffix - A suffix to append to the cacheable key name
  • module - The module name of the view if any
  • args - The arguments to pass into the view
  • collection - The collection this view will iterate on
  • collectionAs - The alias of the collection name
  • collectionStartRow - The start row of the collection iteration
  • collectionMaxRows - The max rows of the collection iteration
  • collectionDelim - The delimiter used for the collection iteration
Executed before a view is about to be rendered
postViewRender All of the data above plus:
  • renderedView - The view contents that was rendered
Executed after a view was rendered

You can disable the view events on a per-rendering basis by passing the prePostExempt argument as true when calling renderView() methods.

Sample Interceptor

Here is a sample interceptor that trims any content before it is renderer:

component{

    function postViewRender(event,interceptData){
        interceptData.renderedView = trim( interceptData.renderedView );
    }
}

Of course, I am pretty sure you will be more creative than that!

results matching ""

    No results matching ""