I set up my modx multi-language sites with each language in a folder, the parent resource is like a "language config" page, it has all the translations for general stuff used in the templates eg. "book now" for buttons, IDs of resources that need to be referenced like "ID of the offers page for this language".
I then have a custom snippet I wrote that checks the parent resource, grabs the TVs and outputs them in a placeholder. Here's the snippet (called [[languageConfig]] btw):
function getConfigTvs($parent) {
global $modx;
$tvs = array();
$resource = $modx->getObject('modResource', $parent);
$tvs = $resource->getMany('TemplateVars');
foreach($tvs as $tv) {
$key = $tv->get('name');
$value = $tv->getValue($parent);
$modx->setPlaceholder('translate.'.$key, $value);
}
}
$parent = $modx->runSnippet('UltimateParent');
getConfigTvs($parent);
In the template you just use [[+translate.bookNow]] where bookNow is a tv with some value specified in the parent resource and make sure you have called the snippet at the top of the template. Now, this all works fine most of the time except occasionally all the placeholders are empty. If I log into the manager and clear the cache all the placeholders are back to normal again, if I use modx with the resource caching turned off this never happens but of course this is not a viable solution for production. I have tried calling the snippet uncached but this doesn't seem to make any difference seeing as it's the resource level caching that seems to cause the issue.
Oh, and in case anybody notices....yes this pretty much the same as using:
[[getResourceField? &id=`[[UltimateParent]]` &field=`bookNow` &processTV=`1`]]
...just a lot shorter markup in the template....so potentially what I need to do is figure out how to make a new snippet call out of getResourceField that always looks at ultimateParent, always processes TVs and just takes a tv name as an option? Seeing as getResourceField works way better than my custom snippet!
Any advice much appreciated.
ps. I have this caching issue on separate sites both locally (MAMP) and online