getgrav / grav-plugin-form

Grav Form Plugin
http://getgrav.org
MIT License
53 stars 79 forks source link

grav cms : twig extension #412

Open mourad-dev79 opened 4 years ago

mourad-dev79 commented 4 years ago

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;

}

}`

`

Les actualités sont extraites du site Digital Learning Academy

{{ includeFile('./../../getData.php') }}
Nous remercions particulièrement le site Digital Learning Academy by IL&DI
et Philippe Lacroix
`
daddyfix commented 4 years ago

I am having the EXACT same issue. Did you ever find a solution?

mahagr commented 4 years ago

Make sure you load the Twig extension from your theme/plugin.

daddyfix commented 4 years ago

Thanks