layoutManager Mach-II plugin
Usage
Place layoutManager.cfc in the MachII plugins folder. Place this in the plugins section of the Mach-II configuration file (typical usage):
<plugin name="layoutManager" type="MachII.plugins.layoutManager"> <parameters> <parameter name="defaultLayoutEvent" value="layout.main" /> <parameter name="finalOutputKey" value="request.content.final" /> </parameters> </plugin>
In the event-handlers section:
<event-handler event="layout.main" access="private"> <view-page name="layout.main" contentKey="request.content.final" /> </event-handler>
This will announce layout.main at the end of the event queue. If you need to use a different layout event (such as for popups where you don’t require the normal site layout) set an event argument named layoutEvent to your chosen alternate layout event name. You can also set an event argument named skipLayoutEvent to true if you wish skip the layout altogether (such as when the output is an XML file or an image).
The final content (contained in request.content.final) will be stripped of all unnecessary whitespace. You can disable this by not setting the finalOutputKey parameter and not specifying a content key for the final layout view.
Plugin parameters
| Parameter | Data type | Opt. | Default | Description |
|---|---|---|---|---|
| defaultLayoutEvent | string | No | N/A | Name of event to be announced at the end of the queue |
| defaultContentType* | string | Yes | text/html; charset=utf-8 | Default content type for output |
| finalOutputKey* | string | Yes | N/A | Name of content key to which the final content is written |
| optimizeWhitespace* | boolean | Yes | true | Enables/disables whitespace optimisation |
| preserveWhitespaceTagList* | list of strings | Yes | pre, textarea | List of tags where content is left untouched by whitespace optimisation |
| defaultDispositionMethod* | string | Yes | attachment | Default disposition method when forcing a download to the browser ("attachment" or "inline") |
| argumentPrefix | string | Yes | empty string | Prefix for all event arguments used by layoutManager |
*These parameters have no effect when the finalOutputKey parameter is omitted.
Event arguments used by layoutManager
Note: Use the argumentPrefix parameter to modify the following argument names. This can be helpful to avoid clashes with other event args such as form and url values. For example, if you set argumentPrefix to "LM_" the following argument names will be LM_layoutEvent, LM_contentType, etc).
| Event argument | Data type | Description |
|---|---|---|
| disableLayoutManager | boolean | When set to true, disables the plugin for the current request |
| layoutEvent | string | Overrides the default layout event for the current request |
| skipLayoutEvent | boolean | When set to true, layoutManager doesn’t announce the layoutEvent (whitespace optimisation and other actions on the final output are still active) |
| contentType* | string | Overrides the default content type for the current request |
| optimizeWhitespace* | boolean | Enables/disables whitespace optimisation for the current request |
| forcedFileName* | string | Pushes the final output as a download and fakes the file name in the "Save as…" dialog |
| dispositionMethod* | string | Overrides the default disposition method for the current request ("attachment" or "inline") |
*These event arguments have no effect when the finalOutputKey parameter is omitted.
Notes
Exceptions
When an exception is thrown and the exception event is announced, layoutManager will still announce the layout event at the end of the queue. If you are using the finalOuputKey method, your exception event has to write content to this content key. If the error was thrown by the layout event, you will get a white screen of death. A possible solution to this would be to add an event mapping in your layout event-handler to redirect all exceptions to an event that disables the layoutManager (using the disableLayoutManager event argument).
CFCONTENT
When using the finalOutputKey method, layoutManager always includes a cfcontent tag just before outputing the content. This means that you shouldn’t use cfcontent elsewhere in your code.
If you have any problems using this plugin don’t hesitate to post comments on this page.

February 10th, 2006 at 11:08 pm
MGW: you’re absolutely right. I haven’t looked at this page in a long time. I can’t even remember whether this was valid in an older version of Mach-II. Was it?
February 10th, 2006 at 10:38 pm
I see code is stripped out. Change event to event-handler and change name= to event=. Also you should probably add access=”private”.
February 10th, 2006 at 10:36 pm
Just checked this out. If you are using Mach II ver 1.1, you need to change the event part to the following:
December 23rd, 2005 at 8:24 pm
I think the problem here is that it should be your layout.main event that writes to request.content.final The final contentKey is the final output of the request. You should use a different contentKey for the content that is nested in your main layout view. Don’t hesitate to write back if this doesn’t work.
December 23rd, 2005 at 11:25 am
Hello,
I have followed the instructions on this page to implement the layout-plugin, but it does not seem to work, or I don’t get it.
When I run a default page event, I place the content in the request.content.final key. The layoutmanager then runs, opens layout.main and should parse the key on my page. But only the content in de first event is shown, never the content from layout.main? Am I missing something? I am using the latest version of Mach-II.