grav-plugin-form
grav-plugin-form copied to clipboard
grav cms : twig extension
i have created a twig extension to include a file php .. this file is a function return a code html that i want to append it to my twig template i have respected the structure in the documentation of GRAV but it dosent work !!
here is my code :
`<?php namespace Grav\Plugin;
class PhpIncludeTwigExtension extends \Twig_Extension {
public function getName()
{
return 'PhpIncludeTwigExtension';
}
public function getFunctions()
{
return [
new \Twig_SimpleFunction('includeFile', [$this, 'exampleFunction'])
];
}
public function exampleFunction(string $file)
{
ob_start();
require_once(dirname(__FILE__).'./'.$file);
$content = ob_get_clean();
return $content;
}
}`
`
<h4 class="fix">Les actualités sont extraites du site Digital Learning Academy</h4>
{{ includeFile('./../../getData.php') }}
</div>
<div class="row justify-content-center">
<div class="col-md-8 text-center">
<h6 class="subtitle">Nous remercions particulièrement le site Digital Learning Academy by IL&DI <br>et Philippe Lacroix</h6>
</div>
</div>
</div>
</div>
</div>`
I am having the EXACT same issue. Did you ever find a solution?
Make sure you load the Twig extension from your theme/plugin.
Thanks