New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asset function is not defined in the context #6
Comments
Hi Raj, although this error seems to be related to Twig itself, I would like to help you with this. But I think, I will need to see the template. It seems you are using a function called 'asset' somewhere. Have you tried removing this function? Does it work without it? |
Hi Sullinger, If I remove that function then my template will not include my assests(js, css, images). Below is the template:
|
Hi Raj, by looking at your template, I guess you are using Assetic for asset management in a Symfony 2 setup. Assetic extends twig by adding the asset function that then can preprocess the defined asset in any way you like. Like some people posted on this issue of the Assetic repo, I don't really see a need for using Assetic with grunt. Instead you should use grunt plugins to replace the usage of Assetic, if possible. You can still use this 'asset' function, but you will have to extend Twig in JavaScript/Grunt as Assetic does extend Twig in PHP/Symfony. Please see the grunt-twig-render readme on how you can add custom functions to Twig. This way, you can define your own 'asset' function and define what should be done with the assets. Hope this points you in the right direction?! Stefan |
Hi, Just for curiosity, what is the output if I compile my twig template with this grunt plugin, because as you see in the error I also have the issue related to extending templates. My actual motive of using this plugin was to feed the generated html file to the usemin plugin, The whole process looks cumbersome; so I am planning to abandon the idea. Raj |
Hi Ray, if you add an asset function that simply outputs the provided string, your Twig task output will be valid HTML files that you can then pass to the usemin plugin. Note: The following is untested / pseudo-code.
Then
should become
|
This is interesting.. let me try this. One more question how can I ignore extended twigs or is there any way to add them in the twig under compilation. Thanks a lot |
So you mean something like a per template extension?
|
Hi, what I do with this:
This causes an error.
|
Hey Raj, using namespaces is not yet supported by the underlying TwigJS library, but there is a pull-request for it, so you might have to wait until it is merged. Stefan |
Is there any way I can write a function and replace it with actual twig template or remove this statement. because I don't add any css or js to my base template Raj |
There are many options. You could try to add another task that replaces this namespace or removes it entirely, for example using https://github.com/erickrdch/grunt-string-replace |
HI there,
I am new to Grunt, I have added below lines to my grunt file.
And got this error
What I am missing??
I am aiming to convert twig templates into html so that I can have all the rendered paths to my assests, which I would feed into usemin and get my assets uglified.
Any suggestions do achieve similar is welcome.
Thanks
Raj
The text was updated successfully, but these errors were encountered: