Nobody?
I'd appreciate any thoughts - if anyone can understand what I'm going on about
Just to restate the problem, and add a bit more info..
THE ISSUE
- All web pages include a banner area
- On specific pages and under specific conditions, a snippet in the content area will set the banner to an image, slider or other markup appropriate for that page.
- If a snippet has NOT set the banner, we want it to be a default image.
ATTEMPT 1 - snippet tag in the template
The 'obvious' solution seems to be a snippet call, eg [[theBanner]] in the template.
PROBLEM: the snippet would need to include lots of disparate logic for selecting the banner depending on the page and other conditions.
This logic should be (and in some cases already is) in individual page snippets.
ATTEMPT 2 - placeholder in the template
(a) default set by plugin
We added a placeholder, eg [+theBanner+] in the template. A snippet in specific pages can then set this placeholder to the correct content.
If the placeholder has NOT been set by a snippet, a plugin should set it to the default image.
PROBLEM: We couldn't find an event to attach the plugin to.
OnWebPageInit ........ happens too soon - the plugin ALWAYS set the default image, before any snippet gets a chance
OnWebPagePrerender ... happens too late - MODX removes the placeholder before this event fires
OnWebPageComplete .... happens too late - MODX removes the placeholder before this event fires
(b) default set by new snippet
We tried replacing the plugin with a "late" snippet call in the template (eg [[defaultBanner]] just before the closing body tag).
We were hoping that any snippet call in the page content would run before the "late" snippet, so the latter would only set the default image if no other snippet had set the placeholder.
PROBLEM: We always get the default image, ie the "late" snippet is being run BEFORE any snippet in the page content.
ATTEMPT 3 - default image in the template
Instead of a placeholder, we put the default image directly in the template, eg <img src="banner_default.jpg" width="100%" />
The snippets in individual pages could then, instead of setting the placeholder, use str_replace to replace this specific string with something else when necessary.
PROBLEM: it doesn't work?
We tried updating $modx->documentOutput (also tried $modx->documentContent) - these strings definitely do contain the text, but changing these variables had no effect on the rendered output.