stefanullinger / grunt-twig-render Goto Github PK
View Code? Open in Web Editor NEWRender twig templates
License: MIT License
Render twig templates
License: MIT License
Hi there,
I am using angularjs with symfony, I need to use {%verbatim%} in my twig template in order to prevent angularjs variables getting render by twig.
When I tries to render twig template with this grunt plugin I gets the below error:
$ grunt twigRender
Running "twigRender:eclipse" (twigRender) task
Error compiling twig template app/templates/Default/summary.html.twig:
TwigException: Unable to parse 'verbatim'
Error parsing twig template app/templates/Default/summary.html.twig:
TypeError: Cannot read property 'forEach' of undefined
at Object.Twig.forEach (C:\xampp\htdocs\eclipse\web\bundles\insighteclipse\node_modules\grunt-twig-render\node_modules\twig\twig.min.js:8:821)
at Twig.parse C:\xampp\htdocs\eclipse\web\bundles\insighteclipse\node_modules\grunt-twig-render\node_modules\twig\twig.min.js:8:7061)
at Twig.Template.render (C:\xampp\htdocs\eclipse\web\bundles\insighteclipse\node_modules\grunt-twig-render\node_modules\twig\twig.min.js:8:11602)
at GruntTwigRender.render (C:\xampp\htdocs\eclipse\web\bundles\insighteclipse\node_modules\grunt-twig-render\tasks\twigRender.js:108:45)
at C:\xampp\htdocs\eclipse\web\bundles\insighteclipse\node_modules\grunt-twig-render\tasks\twigRender.js:191:16
at Array.forEach (native)
at Object.<anonymous> (C:\xampp\htdocs\eclipse\web\bundles\insighteclipse\node_modules\grunt-twig-render\tasks\twigRender.js:181:16)
at Object.<anonymous> (C:\xampp\htdocs\eclipse\web\bundles\insighteclipse\node_modules\grunt\lib\grunt\task.js:264:15)
at Object.thisTask.fn (C:\xampp\htdocs\eclipse\web\bundles\insighteclipse\node_modules\grunt\lib\grunt\task.js:82:16)
at Object.<anonymous> (C:\xampp\htdocs\eclipse\web\bundles\insighteclipse\node_modules\grunt\lib\util\task.js:301:30)
File app/html/Default/summary.html created.
File app/html/Sample/sample.html created.
Below is the code I am using to to render twig template:
twigRender: {
eclipse: {
files : [
{
data: {
greeting: "Hello",
target: "world"
},
expand: true,
cwd: '<%= yeoman.app %>/templates',
src: ['**/*.twig', '!**/_*.twig'], // Match twig templates but not partials
dest: '<%= yeoman.app %>/html',
ext: '.html'
}
],
options:{
extensions:[
function(Twig){
Twig.exports.extendFunction( "asset", function( source ){
return source.split('insighteclipse/')[1];
});
Twig.exports.extendFunction( "path", function( source ){
return source;
});
}
]
}
},
},
Below is the part of template where I am using {% verbatim %}
<section class="col-sm-9">
<article class="thumbnail" id="content">
<div class="alert alert-info text-center" id="unit">WH-2500</div>
<div class="table-responsive" id="overview"></div>
<div class="" id="detail" data-ng-controller="censusCtrl">
<table class="table table-stripped">
<thead>
<tr>
<th data-ng-repeat = "(key,value) in fields">{% verbatim %}{{key}}{% endverbatim %}</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat = "record in records">
<td data-ng-repeat = "(key,value) in record">{% verbatim %}{{value}}{% endverbatim %}</td>
</tr>
</tbody>
</table>
</div>
</article>
</section>
Any help
Raj
Update:
I have found the work around by reading this post - http://stackoverflow.com/questions/10834390/angularjs-on-a-symfony2-application
But I would like to use {% verbatim %}, so can we have support for this?
Hi there,
is there any way to use wildcards for data file paths? I tried someting like this:
files : [{
data: ['mypath/twig/data/**/*.json']
// ...
}]
Unfortunately it doesn't work like expected.
Thanks
Philipp
Install all dependencies inside a node_modules folder inside of grunt-twig-render folder, instead of installing on the root?
Can you update to the latest version of twig?
Thanks in advance. ๐
Hi, I'm facing some issues using some syntax and option of twig with the the grunt-twig-render.
I guess this is happening why I'm trying to use twig logic from version ^2.0 (as usually use on real php projects) on a project with this twig "wrapper", that it seems using twig version 1 (for me now is 1.13.2).
So my question: there is a way to set which twig version the grunt-twig-render should use?
Could I set to use twig version 2.x.x?
On mac/linux, including a file using e.g. {% extends '../common/templates/index.twig' %}
works as intended: the path is resolved relative to the template being processed.
On windows, the path seems to be resolved relative to the Gruntfile, which means that while the above works fine everywhere else, it breaks when executed there.
Hi, is it possble to set the twigjs cache to false? If not this should be implemented.
HI there,
I am new to Grunt, I have added below lines to my grunt file.
module.exports = function (grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Configurable paths for the application
var appConfig = {
app: require('./bower.json').appPath || 'web/bundles/insighteclipse/app',
dist: 'dist'
};
// Define the configuration for all the tasks
grunt.initConfig({
// Project settings
yeoman: appConfig,
twigRender: {
your_target: {
files : [
{
data: {
greeting: "Hello",
target: "world"
},
template: 'src/Insight/EclipseBundle/Resources/views/Default/sample.html.twig',
dest: '<%= yeoman.dist %>/demo/sample.html.twig'
}
]
},
},
});
grunt.loadNpmTasks('grunt-twig-render');
};
And got this error
Running "twigRender:your_target" (twigRender) task
Error parsing twig template src/Insight/EclipseBundle/Resources/views/Default/sa
mple.html.twig:
TwigException: asset function does not exist and is not defined in the context
Error parsing twig template src/Insight/EclipseBundle/Resources/views/Default/sa
mple.html.twig:
TwigException: asset function does not exist and is not defined in the context
Warning: ENOENT, no such file or directory 'C:\xampp\htdocs\eclipse\InsightEclip
seBundle::base.html.twig' Used --force, continuing.
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
When I try to call a variable from my data.json
file in an imported macro it doesn't output anything. The variable displays fine if I call it in the base template, just not the macro. I don't get any errors in the console.
data.json
File:
{
"logoPath": "/assets/img/logo.svg"
}
Macro Template:
{% macro logo() %}
<img src="{{ logoPath }}" alt="my logo">
{% endmacro %}
Base Template:
{% import '@templatePath/_macros/helpers.twig' as helpers %}
<header>
{{ helpers.logo() }}
</header>
Result:
<img src="" alt="my logo">
Here's my Gruntfile config:
twigRender: {
dev: {
options: {
namespaces: { 'templatePath': 'src/templates' }
},
files : [
{
data: 'src/templates/data.json',
expand: true,
cwd: 'src/templates/',
src: ['**/*.twig', '!**/_*.twig', '!_*/*.twig', '!_*/**/*.twig'],
dest: 'src/html/',
ext: '.html'
}
]
}
}
There are certain times where I want to return the output of a rendered template as a string, which I can then set as the value of a variable.
E.g. Rather than have {% include "path/to/partial" with {foo: 'bar'} only %}
I would want to have {% set myVar = include("path/to/partial", {foo: "bar"}, false) %}
Although I've used this without problems on other websites using Twig (e.g. Craft CMS), it doesn't look like this functionality is available with this package? When I try to use include as a function, I get the following error in my terminal:
TwigException: include function does not exist and is not defined in the context
I'm assuming there is a way around this by adding Twig.exports.extendFunction('include', ...)
to the grunt config for the task, but I'm having trouble working this out. Any help would be appreciated.
In my Gruntfile, I have:
data: {
body: 'Hello, World!',
title: 'Hello, World!'
},
In my Twig template, I have:
<title>{{ title }}</title
<body>
{% block body %}{% endblock %}
</body>
The title
is populated as expected, but the body
appears to fail silently. Are blocks not supported, or am I missing something?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.