twig.js
twig.js copied to clipboard
support include function
The include()
functions is equivalent to the include
tag. It breaks twig.js with "Cannot call method 'replace' of undefined."
Example:
{{ include('template.html', {foo: 'bar'}, with_context = false) }}
{% include 'template.html' with {'foo': 'bar'} only %}
http://twig.sensiolabs.org/doc/functions/include.html
edit following https://github.com/twigjs/twig.js/issues/392#issuecomment-1670209897: I don't recall why this was closed. reopening
@olets, it does? What am I missing? I get:
TwigException: include function does not exist and is not defined in the context
I've added this to the implementation notes on the wiki. https://github.com/twigjs/twig.js/wiki/Implementation-Notes
Why was this closed? The include function is the recommended method of inclusion, according to the docs:
Note: It is recommended to use the include function instead as it provides the same features with a bit more flexibility
If this is still not supported, it should be reopened.
Hello , any update here ?
If someone is able to provide a TwigFiddle example that works and an example using this template that does not work, then I can look into it more.
Hey @willrowe
Here's the TwigFiddle showing the include() working as expected.
Here's the TwigJS version erroring out.
From the console:
TwigException: include function does not exist and is not defined in the context
Simple question: how can I use the include() function when the main template as been rendered from a string:
https://github.com/Geolim4/In-Memoriam/blob/60412b8730f68ecf2005c3694e41fdbb73254927/src/ts/Extensions/renderer.ts#L92
Should include() get implemented as a callback function on my own when Twig render is called on a string instead of a filename ?
@Geolim4 you can't use the include
function because it is not currently supported. This issue is for adding support for it.
@Geolim4 you can't use the
include
function because it is not currently supported. This issue is for adding support for it.
Ohhh okay, so the readme is a bit lying then -_-
the readme is a bit lying then
What do you mean?
The implementation note says that "include" is supported while its not actually :(
https://github.com/twigjs/twig.js/wiki/Implementation-Notes
I've added this to the implementation notes on the wiki. https://github.com/twigjs/twig.js/wiki/Implementation-Notes
@JohnAlbin did you update the implementation notes when you were under the impression that support had been added?
@willrowe I think you are misreading the docs. The include
tag is listed as supported. I added the note about the include
function that says:
include
: Throws error: "include function does not exist and is not defined in the context" https://github.com/twigjs/twig.js/issues/392
@JohnAlbin great, thanks for the clarification.
@Geolim4 the implementation notes are correct. It says that the include
tag is supported and the include
function is not.
@willrowe I think you are misreading the docs. The
include
tag is listed as supported. I added the note about theinclude
function that says:
include
: Throws error: "include function does not exist and is not defined in the context" https://github.com/twigjs/twig.js/issues/392
Hello,
I'm then asking again how to include a twig file and make it work ?
I do have this kind of error:
While my implementation looks like this:
Is there a path/context to provide to make it work ?
@Geolim4 this issue is for adding support for the include
function, not for general troubleshooting.
@Geolim4 this issue is for adding support for the
include
function, not for general troubleshooting.
Still, the include tag is either unclear or not enough documented, so I think its indirectly related ?
@Geolim4 this issue is a feature request. Please search through the existing issues and documentation. If there is nothing in there related to what you want to do then open a new issue.
Hi @willrowe, are there any update on this include
function implementation?
@Dru-S I have not had a chance to work on this yet, but if you want to submit a PR I will review it.