Ive seen a lot of people asking this question with no good answer;
maybe there is a way to do it using Coldbox. I need to mimic the
CFHTMLHEAD tag but instead of putting content before the closing HEAD
tag, I need to put content before the closing BODY tag.
I'm wondering if there is a way to do this using Coldbox's
onRequestEnd or another approach. I would need to put the content in
dynamically (sometimes put it in, sometimes not depending on criteria,
just like CFHTMLHEAD). I just dont know what I would need to tap into
to get access to the generated content.
Yeah, the code can change, depending on other criteria (what site Im
on, a database flag, something). Right now Im trying the approach of
instead of calling SetLayout with the actual layout, Im calling a
custom template that includes the regular layout but does a
CFSAVECONTENT and then injects code before the closing BODY tag.
Messy, but Im struggling for options!
One way would be to simply put a variable called #rc.bodyend# or
whatever just above your body tag in your layout and then just populate
that variable with whatever you need included via your handler.
<cfparam> it to blank in the cases where you don't need anything.
Curt: Yes, a good idea. In our case, though, we have several hundred
different templates that get called based on specific criteria, and we
wanted to have a way to inject code (like CFHTMLHEAD) across all
requests.
You can also get more funky and run an interceptor in your layouts before the body end tag:
#announceInterception(“preBody”)#
Then you can create interceptors that will be able to use the interceptor request buffer to add things at the end. The good thing about this, is that you can create decoupled objects that react to the preBody tag. You can stack them, organize them and grow it easily.