I am trying to render templates in Symfony wi开发者_Go百科th a CSS class to denote which part of the site they belong to. For example: I am in /games
I'd like the page to look something like:
<div id="wrapper" class="games">
<!-- content -->
</div>
Or if we are displaying /home/profile
the page would look like this:
<div id="wrapper" class="home">
<!-- content -->
</div>
Basically I am looking for a similar functionality to CodeIgniter's url segment methods.
Is the class simply the name of the module? If it is, do this:
<div class="<?php echo $sf_context->getModuleName() ?>">
You could also set it as a parameter on the request by defining it in your routes:
page:
url: /page
param: { module: default, action: page, section: games }
...
Then get it off the request in your template:
<div class="<?php echo $sf_request['section'] ?>">
Finally, if it's the same for each module but not equivalent to the module name, you could set it in preExecute
:
public function preExecute()
{
$this->getRequest()->setParameter('section', 'workouts');
}
精彩评论