grav-plugin-form icon indicating copy to clipboard operation
grav-plugin-form copied to clipboard

grav cms : twig extension

Open mourad-dev79 opened this issue 4 years ago • 3 comments

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>`

mourad-dev79 avatar Mar 06 '20 13:03 mourad-dev79

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

daddyfix avatar Apr 25 '20 14:04 daddyfix

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

mahagr avatar May 04 '20 07:05 mahagr

Thanks

daddyfix avatar May 05 '20 12:05 daddyfix