simon-dt / gulp-twig

Twig plugin for gulp.js, The streaming build system. Looking for maintainer or collaborators. See wiki
https://github.com/zimmen/gulp-twig/wiki/Looking-for-maintainer-or-collaborator(s)
MIT License
62 stars 33 forks source link

Error parsing twig template #13

Closed iGitScor closed 9 years ago

iGitScor commented 9 years ago

I'm having an issue with using filter and compiling my twig.

I got the follwoing error :

Error parsing twig template /home/[...]/Documents/dev/[...]/sources/plain/views/index.twig: 
Unable to find filter trans

The problem is here :

{{ 'amazing' | trans() }}

Here my gulp task :

gulp.src(source.split(','))
        .pipe($.data(function () {
          var content = {};
          if (config.content !== 'no') {
            var contentPath = path.join(process.cwd(), config.contentPath);
            fs.readdirSync(contentPath).forEach(function (file) {
              var filePath = path.join(contentPath, file);
              if (path.extname(file) === '.json') {
                // No cache for template content
                delete require.cache[require.resolve(filePath)];
                content = _.merge(content, require(filePath));
              }
            });
          }
          return content;
        }))
        .pipe($.twig({
          filters: [
            {
              name: "trans",
              func: function (args) {
                return "the function";
              }
            }
          ]
        }))
        .pipe(gulp.dest(dist));

I'm trying to reproduce Symfony2 behavior

mowcixo commented 9 years ago

That's because, the trans() function its a Symfony2 extension over Twig... you can see all the Twig.js supported functionality at https://github.com/justjohn/twig.js/wiki/Implementation-Notes

By the way... in your code, if you change the "filters" key, by "functions", it could work.

iGitScor commented 9 years ago

I know trans is a Symfony2 extension. Even if I change trans as a function, I get the same mesage (Unable to find filter trans)

mowcixo commented 9 years ago

What version are you using in your package.json?, there is no tag for the "filters" support... so you have to use:

"gulp-twig": "*"

Another thing... the $.twig var is equals to: require('gulp-twig') I suppose.

iGitScor commented 9 years ago

In my package.json : "gulp-twig": "^0.3.0"

Yes, $.twig = require('gulp-twig')

mowcixo commented 9 years ago

That's because of the tag in the repo or in npm... maybe @zimmen can handle this.

simon-dt commented 9 years ago

Hi @iGitScor , You can update the package.json to "gulp-twig":"^0.4.0" ( or "gulp-twig":"*" although this could bring in breaking changes some day )

Thanks for the heads-up @mowcixo

mowcixo commented 9 years ago

With this changes it has to work @iGitScor. Thanks @zimmen.

iGitScor commented 9 years ago

Yes, it works ! Thanks