I'm working with Symfony2 and:
I have this in the routing.yml
_welcome: resource: "@AcmeBundle/Controller/" type: annotation
I this method within a controller:
/** * @Route("/{page}") */ public function staticAction($page) { return $this->render('AcmeBundle:Static:'.$page.'.html.twig'); }
To generate common pages:
/home /contact /privacy
But when I make the url on the menu:
<a href="{{ path('_welcome', {'page': 'home'}) }}">Home</a> <a href="{{ path('_welcome', {'page': 'contact'}) }}">Contact</a> <a href="{{ path('_welcome', {'page': 'privacy'}) }}">Privacy</a>
And I Symfony generates these urls:
…./?page=home …./?page=contact …./?page=privacy
And the right would be:
/home /contact /privacy
What must I do?
You can get the current URL in Twig/Silex 2 like this: global. request. attributes. get('_route') .
Twig is a modern template engine for PHPSecure: Twig has a sandbox mode to evaluate untrusted template code. This allows Twig to be used as a template language for applications where users may modify the template design.
Twig works by taking all the hocus pocus out of template design. Templates are basically just text files that contain variables or expressions that are replaced by values as the template is evaluated. Tags are also an important part of a template file, as these control the logic of the template itself.
You've to add a route name in your controller route annotations as follow,
/** * @Route("/{page}", name="static") */ public function staticAction($page) { // ... }
You could then call the twig path
helper using that name,
<a href="{{ path('static', {'page': 'home'}) }}">Home</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With