Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pimcore] introduce twig placeholder #827

Merged
merged 1 commit into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions docs/02_Components/Pimcore_Component.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CoreShop Pimcore Component
f# CoreShop Pimcore Component

## Features

Expand Down Expand Up @@ -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\')'});
Expand All @@ -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
Expand Down Expand Up @@ -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 %}
```
```
45 changes: 45 additions & 0 deletions src/CoreShop/Component/Pimcore/Placeholder/Twig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Component\Pimcore\Placeholder;

use Pimcore\Placeholder\AbstractPlaceholder;

class Twig extends AbstractPlaceholder
{
/**
* {@inheritdoc}
*/
public function getTestValue()
{
return '<span class="testValue">Name of the Object</span>';
}

/**
* {@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,
]);
}
}