I have a library of widgets (js and other files) which instead of writing
{% include 'path' %}
all the time I have written an extension to just include them with a function call like so:
{% widget('name') %}
So my question is how do I re implement the twig include function? Is it just a matter of returning a php include or is it a file_get_contents?
Examples:
<?php
class Extensions
{
public function widget($name)
{
return include 'filepath/' . $name . '.html.twig';
// or
return file_get_content('filepath/' . $name . '.html.twig');
}
}
Thank you
Updated: I'm using file_get_contents and I get the following returned:
alert('FROM HERE');
// AS
alert('FROM HERE');