twigjs / twig.js

JS implementation of the Twig Templating Language
BSD 2-Clause "Simplified" License
1.88k stars 275 forks source link

support include function #392

Open olets opened 8 years ago

olets commented 8 years ago

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

hawkeyetwolf commented 7 years ago

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

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

JohnAlbin commented 3 years ago

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

Bilge commented 3 years ago

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.

MothannaDoubaa commented 1 year ago

Hello , any update here ?

willrowe commented 1 year ago

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.

bronzehedwick commented 1 year ago

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
Geolim4 commented 11 months ago

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 ?

willrowe commented 11 months ago

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

Geolim4 commented 11 months ago

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

willrowe commented 11 months ago

the readme is a bit lying then

What do you mean?

Geolim4 commented 11 months ago

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

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

willrowe commented 11 months ago

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?

JohnAlbin commented 11 months ago

@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

willrowe commented 11 months ago

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

Geolim4 commented 11 months ago

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

willrowe commented 11 months ago

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

Geolim4 commented 11 months ago

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

willrowe commented 11 months ago

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

Dru-S commented 7 months ago

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

willrowe commented 7 months ago

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