1
votes

I'm adding a script into my twig file, to redirect to other route.

<script>
$('#lnkPanel').click(function(e) {
    e.preventDefault();
    window.location = '{{ path('profile/' ~ user.id ~ '') }}';
});

But when my twig is rendering I get an error and this not show my page. Error is: "An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "profile/{1}" as such route does not exist.")"

How can I do to not get an error while is rendering twig, and show my page correctly??

Thanks!

2

2 Answers

0
votes

If you are using SlimnViews TwigExtension you should be able to get it running like

<script>
$('#lnkPanel').click(function(e) {
    e.preventDefault();
    window.location = '{{ siteUrl('/profile/') }}{{user.id|e}}/';
});
</script>

Replace {{user.id|e}} with the Twig variable you have for user's profile ID.

0
votes

In the twig path function, it should be your route name :

window.location = '{{ path('profile_route_name', {id: user.id}) }}';