JMSTwigJsBundle icon indicating copy to clipboard operation
JMSTwigJsBundle copied to clipboard

Cannot add runtime filter/functions

Open pinkeen opened this issue 12 years ago • 2 comments

I am using the bundle with assetic integration.

When I introduce a new filter/function to a template then when doing assetic:dump TwigJS produces an error indicating that a filter/function is missing and refuses to compile the template.

This way the template won't even reach the "runtime" phase when I can register the used filter/function.

UPDATE: I did a bit of research and it seems that in order to define any compile time/runtime filters/functions they have to be already present in Twig to avoid the compilation error. Is this an intended behavior? It seems a bit illogical to me. Even if haven't used TwigJS for Single Page App I can imagine plenty of situation when you want some filters/functions in JS which don't belong to standard PHP Twig.

pinkeen avatar Apr 30 '13 14:04 pinkeen

I'm not saying this isn't possible (I'm no expert)... but I thought a big feature of this project was that you could decide at any time to change where it renders, from the client to the server and vice versa. If you start making templates that only compile on the client, then what's the point? I've only ever added runtime filters myself to mimic server-side ones like date, dump, etc.

adam-lynch avatar Jan 07 '14 10:01 adam-lynch

You're right. This feature is one of the main selling points of TwigJS, but IMHO the inability to comfortably use it as a client-side only scripting language seriously limits its usefullness in other scenarios.

The thing is this behaviour is (or was at the time of filing this issue) undocumented.

I worked around this by writing dummy server-side filters/functions. This approach can introduce nasty bugs in the future.

There are a lot of scenarios where server-side functions cannot be ported to JS and vice-versa. And they always will be there. Moving templates between server and client will never be a trivial out-of-the-box process so it can't be expected that one will simultaneously implement the same filters/functions server and client side. It's just too much unnecessary work.

Anyway this is just my two cents. Not every project has to fit all scenarios and TwigJS will probably fill its niche.

pinkeen avatar Jan 07 '14 11:01 pinkeen