Greetings,
thank you for the wonderful work so far. I am setting Mautic as a marketing suite for an ecomm operating in 15+ countries and template localization is a big feature for me. With your plugin I was able to bake into my grapejs templates references to dynamic content for the message generation(mostly footers and impressum). Although it became apparent that these includes are 'strict' without attempt to get their translated entities for leads(contacts) which have their preferred locale set.
After a few hours into code inspection I was able to modify the plugin as to fetch the translated entities for dynamic content and it works. Yet in a very hacky way using PHP globals to pass the lead from EmailSubscriber to Twig_Loader_DynamicContent.
Basically this in TemplateProcessor.php :
private function findTemplate($resourceAlias)
{
$model = $this->modelFactory->getModel('dynamicContent');
$result = $model->getEntities(
[
'filter' => [
'where' => [
[
'col' => 'e.name',
'expr' => 'eq',
'val' => $resourceAlias,
],
[
'col' => 'e.isPublished',
'expr' => 'eq',
'val' => 1,
]
]
],
'ignore_paginator' => true,
]);
if (count($result) === 0) {
return null;
}
/**** The result array key is the dynamic content ID - So use array_keys and get the first (and only) found key ****/
$keys = array_keys($result);
$originalEntity = $result[$keys[0]];
$translatedEntity = $model->getTranslatedEntity($originalEntity,$GLOBALS['lead']);
$this->logger->debug("Templates: The resolved base entity is :".print_r($translatedEntity[1]->getId(),true));
$this->logger->debug("Templates: The current lead prefered locale is:".$GLOBALS['lead']['id'] . " and locale is :".$GLOBALS['lead']['preferred_locale'] );
return $translatedEntity[1];
}
Would you care to hint a more elegant way of passing the Lead down the Twig chain?
And would you plan merging such a feature into master for the community?
Greetings, thank you for the wonderful work so far. I am setting Mautic as a marketing suite for an ecomm operating in 15+ countries and template localization is a big feature for me. With your plugin I was able to bake into my grapejs templates references to dynamic content for the message generation(mostly footers and impressum). Although it became apparent that these includes are 'strict' without attempt to get their translated entities for leads(contacts) which have their preferred locale set. After a few hours into code inspection I was able to modify the plugin as to fetch the translated entities for dynamic content and it works. Yet in a very hacky way using PHP globals to pass the lead from EmailSubscriber to Twig_Loader_DynamicContent. Basically this in TemplateProcessor.php :
And then in Twig_Loader_DynamicContent:
Would you care to hint a more elegant way of passing the Lead down the Twig chain? And would you plan merging such a feature into master for the community?
Regards, Daniel