I am building a simple application using Symfony. The page layout consists of a main body with left and right sidebars. The sidebars contains several modules which are user configurable.
Symfony provides slots which seem to be the correct way to fill the sidebars:
layout.php
<div id="left_sidebar">
<?php if (has_slot('left_sidebar')): ?>
<ul>
<?php include_slot('left_sidebar') ?>
</ul>
<?php else: ?>
<!-- default sidebar code -->
<?php endif; ?>
</div>
To fill the slots I tried using a filter. The problem is that some modules in the sidebars depend on what happens in the actions (category updates etc). So they should be generated after the action has run to completion.
msBootstrapFilter
class msBootstrapFilter extends sfFilter
{
public function execute($filterChain)
{
// Generating the sidebars at this point is TOO early
// as the content of some sidebars depends on the actions
// Execute next filter
$filterChain->execute();
// Generate the sidebars after running through all the code
// This is TOO LATE, the layout has been rendered
$this->generateSidebars();
}
}
I do not want to add a “run sidebar” call to each action as that seems inflexible.
What is the best point in the Symfony event flow to generate the sidebar content ? Is there a suitable event that I can connect to?
You can use a component? Which basically is a slot with some sort of action attached to it. In your action you can do whatever your logic needs and render it in the same way as above, but with more logic.
From the manual: