PHP code example of heimrichhannot / contao-twig-support-bundle
1. Go to this page and download the library: Download heimrichhannot/contao-twig-support-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
heimrichhannot / contao-twig-support-bundle example snippets
class CustomContainer
{
/**
* @var HeimrichHannot\TwigSupportBundle\Filesystem\TwigTemplateLocator
*/
protected $templateLocator;
public function onTemplateOptionsCallback()
{
return $this->templateLocator->getTemplateGroup('subscribe_button_');
}
}
use HeimrichHannot\TwigSupportBundle\Filesystem\TwigTemplateLocator;
use Twig\Environment;
function showTemplateLocatorUsage(TwigTemplateLocator $templateLocator, Environment $twig) {
$twigTemplatePath = $templateLocator->getTemplatePath('my_custom_template');
$buffer = $twig->render($twigTemplatePath, ['foo' => 'bar']);
}
use HeimrichHannot\TwigSupportBundle\Renderer\TwigTemplateRenderer;
use HeimrichHannot\TwigSupportBundle\Renderer\TwigTemplateRendererConfiguration;
class MyCustomController {
/** @var TwigTemplateRenderer */
protected $twigTemplateRenderer;
public function renderAction(string $templateName = 'mod_default', array $templateData = []): string
{
$buffer = $this->twigTemplateRenderer->render($templateName, $templateData);
// Or pass some configuration:
$configuration = (new TwigTemplateRendererConfiguration())
->setShowTemplateComments(false)
->setTemplatePath('@AcmeBundle/module/mod_custom.html.twig')
->setThrowExceptionOnError(false);
return $this->twigTemplateRenderer->render($templateName, $templateData, $configuration);
}
}
use HeimrichHannot\TwigSupportBundle\Template\TwigFrontendTemplate;
$template = new TwigFrontendTemplate('my_custom_template');
$template->setData(['foo' => 'bar']);
return $template->getResponse();