Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Pre-compiled js path and url support #22

Open
Josiah opened this issue Mar 21, 2013 · 1 comment
Open

Proposal: Pre-compiled js path and url support #22

Josiah opened this issue Mar 21, 2013 · 1 comment

Comments

@Josiah
Copy link

Josiah commented Mar 21, 2013

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.

@schmittjoh
Copy link
Owner

I like the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants