twigjs / twig.js

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

Unable to parse '='bar')' #410

Open abelmokadem opened 8 years ago

abelmokadem commented 8 years ago

Right now we are using some functions that allow named arguments. Unfortunately this can't be rendered using Twig.js, is there a way to still support this?

e.g.

<div class="cc-alert__content">

    {{ ui_atom('icons/icon', foo='bar') }}

</div>

Twig version used: 0.9.5

Error message:

Error compiling twig template alert.twig: 
TwigException: Unable to parse '='bar')' at template position25
Error parsing twig template alert.twig: 
TypeError: Cannot read property 'forEach' of undefined
    at Object.Twig.forEach (/Users/ashbelmokadem/Projects/dev-machine/crowdcube-web/node_modules/twig/twig.js:151:24)
    at Twig.parse (/Users/ashbelmokadem/Projects/dev-machine/crowdcube-web/node_modules/twig/twig.js:830:19)
    at Twig.Template.render (/Users/ashbelmokadem/Projects/dev-machine/crowdcube-web/node_modules/twig/twig.js:1267:30)
    at /Users/ashbelmokadem/Projects/dev-machine/crowdcube-web/node_modules/kss/builder/base/twig/kss_builder_base_twig.js:554:39
    at tryCatcher (/Users/ashbelmokadem/Projects/dev-machine/crowdcube-web/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/ashbelmokadem/Projects/dev-machine/crowdcube-web/node_modules/bluebird/js/release/promise.js:504:31)
    at Promise._settlePromise (/Users/ashbelmokadem/Projects/dev-machine/crowdcube-web/node_modules/bluebird/js/release/promise.js:561:18)
    at Promise._settlePromiseCtx (/Users/ashbelmokadem/Projects/dev-machine/crowdcube-web/node_modules/bluebird/js/release/promise.js:598:10)
    at Async._drainQueue (/Users/ashbelmokadem/Projects/dev-machine/crowdcube-web/node_modules/bluebird/js/release/async.js:143:12)
    at Async._drainQueues (/Users/ashbelmokadem/Projects/dev-machine/crowdcube-web/node_modules/bluebird/js/release/async.js:148:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/ashbelmokadem/Projects/dev-machine/crowdcube-web/node_modules/bluebird/js/release/async.js:17:14)
    at tryOnImmediate (timers.js:534:15)
    at processImmediate [as _immediateCallback] (timers.js:514:5)
dave-irvine commented 8 years ago

Looks like named arguments landed in Twig in 1.12, its not something we support yet but I'd love a PR to add it!

abelmokadem commented 8 years ago

Sweet! Would love to take some time outside of work to get this in. I'll have a look into this later this week.

arakwar commented 4 months ago

Any news on this?

willrowe commented 3 months ago

@arakwar it is not being worked on currently, feel free to create a PR.