From 5f7e7ef77768d915aff0b146af241855eff1b99a Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Wed, 20 Feb 2019 16:16:52 +0100 Subject: [PATCH] [Pimcore] introduce twig placeholder --- docs/02_Components/Pimcore_Component.md | 19 +++++++- .../Component/Pimcore/Placeholder/Twig.php | 45 +++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/CoreShop/Component/Pimcore/Placeholder/Twig.php diff --git a/docs/02_Components/Pimcore_Component.md b/docs/02_Components/Pimcore_Component.md index 0884e897de..5f4033ba29 100644 --- a/docs/02_Components/Pimcore_Component.md +++ b/docs/02_Components/Pimcore_Component.md @@ -1,4 +1,4 @@ -# CoreShop Pimcore Component +f# CoreShop Pimcore Component ## Features @@ -157,6 +157,7 @@ SharedTranslation::add('key', 'en', 'value'); ### Placeholder Features CoreShop also extends Pimcores Placeholder features with an additional feature to use the Symfony Expression Language. +#### Expression Placeholder ``` %Expression(expression, {'expression' : 'parameter(\'kernel.environment\')'}); @@ -174,6 +175,20 @@ CoreShop also extends Pimcores Placeholder features with an additional feature t %Expression(expression, {'expression' : 'service(\'coreshop.money_formatter\').format(100, \'EUR\', \'en\')'}); ``` +#### Twig Placeholder + +``` +%Twig(keyOfParams, {'template' : ':Mail/includes:files.html.twig'}); +``` + +This will render your twig view with following parameters: + + - keyOfParams: valueForKeyOfParams + - value: valueForKeyOfParams + - config: Placeholder Config + - params: all params available in the mail + - placeholder: object for the placeholder + ### Routing Features #### Link Generator @@ -258,4 +273,4 @@ These tests let you test if a certain object is a Pimcore DataObject or a DataOb {% if product is object_class('Product') %} {# product is of a Product DataObject #} {% endif %} -``` \ No newline at end of file +``` diff --git a/src/CoreShop/Component/Pimcore/Placeholder/Twig.php b/src/CoreShop/Component/Pimcore/Placeholder/Twig.php new file mode 100644 index 0000000000..61e50b3896 --- /dev/null +++ b/src/CoreShop/Component/Pimcore/Placeholder/Twig.php @@ -0,0 +1,45 @@ +Name of the Object'; + } + + /** + * {@inheritdoc} + */ + public function getReplacement() + { + $twig = \Pimcore::getContainer()->get('twig'); + $config = $this->getPlaceholderConfig(); + $template = $config->get('template'); + + return $twig->render($template, [ + $this->getPlaceholderKey() => $this->getValue(), + 'value' => $this->getValue(), + 'key' => $this->getPlaceholderKey(), + 'config' => $this->getPlaceholderConfig()->toArray(), + 'params' => $this->getParams(), + 'placeholder' => $this, + ]); + } +}