twig.js icon indicating copy to clipboard operation
twig.js copied to clipboard

support include function

Open olets opened this issue 8 years ago • 20 comments

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 avatar Jun 29 '16 19:06 olets

@olets, it does? What am I missing? I get:

TwigException: include function does not exist and is not defined in the context

hawkeyetwolf avatar Apr 04 '17 14:04 hawkeyetwolf

I've added this to the implementation notes on the wiki. https://github.com/twigjs/twig.js/wiki/Implementation-Notes

JohnAlbin avatar Apr 08 '21 07:04 JohnAlbin

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.

Bilge avatar Jun 22 '21 22:06 Bilge

Hello , any update here ?

MothannaDoubaa avatar May 28 '23 15:05 MothannaDoubaa

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.

willrowe avatar Jun 02 '23 17:06 willrowe

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

bronzehedwick avatar Aug 08 '23 19:08 bronzehedwick

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 avatar Oct 06 '23 19:10 Geolim4

@Geolim4 you can't use the include function because it is not currently supported. This issue is for adding support for it.

willrowe avatar Oct 11 '23 14:10 willrowe

@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 -_-

Geolim4 avatar Oct 11 '23 15:10 Geolim4

the readme is a bit lying then

What do you mean?

willrowe avatar Oct 11 '23 15:10 willrowe

The implementation note says that "include" is supported while its not actually :(

https://github.com/twigjs/twig.js/wiki/Implementation-Notes

Geolim4 avatar Oct 11 '23 15:10 Geolim4

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 avatar Oct 11 '23 15:10 willrowe

@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 avatar Oct 11 '23 16:10 JohnAlbin

@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 avatar Oct 11 '23 16:10 willrowe

@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

Hello,

I'm then asking again how to include a twig file and make it work ? I do have this kind of error: image

While my implementation looks like this: image image

Is there a path/context to provide to make it work ?

Geolim4 avatar Oct 11 '23 19:10 Geolim4

@Geolim4 this issue is for adding support for the include function, not for general troubleshooting.

willrowe avatar Oct 11 '23 19:10 willrowe

@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 avatar Oct 11 '23 19:10 Geolim4

@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.

willrowe avatar Oct 11 '23 19:10 willrowe

Hi @willrowe, are there any update on this include function implementation?

Dru-S avatar Feb 19 '24 11:02 Dru-S

@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.

willrowe avatar Feb 20 '24 14:02 willrowe