JMSTwigJsBundle icon indicating copy to clipboard operation
JMSTwigJsBundle copied to clipboard

Proposal: Pre-compiled js path and url support

Open Josiah opened this issue 11 years ago • 1 comments

I'm proposing to build the routing functions (path and url) as javascript closures which will negate the need for any 3rd party libraries such as the FOSJsRoutingBundle.

If the parser were to provide the ability to define 'compiled functions' whereby instead of a function call, the behavior of the function is simulated in a closure or single use function.

Take the following scenario:

{# Twig Template #}
<a href="{{ path('foo_route', {bar: baz}) }}">Foo</a>
sb.append("<a href=\"");
sb.append((function(params){
    return "/foo/"+(params.bar||"");
})({bar: context ? context["baz"] : null});

The way that the route is comprised can be derived from the compiled route. Any need to share potentially sensitive routing information is negated by the fact that this would have been shared anyway as part of the template.

I'm happy to put some code to this if you're open to it.

Josiah avatar Mar 21 '13 21:03 Josiah

I like the idea.

schmittjoh avatar Mar 21 '13 21:03 schmittjoh