Widgets the Symfony way <p>What is "the Symfony way" of creating reusable widgets?</p> <p>By widget I mean an object with behavior defined in PHP and associated template that can be rendered on different pages (controller actions). </p> <p>E.g. tag cloud widget:</p> <pre><code>// TagCloudWidget.php class TagCloudWidget { /** @var PDO */ private $connection; public function __construct(PDO $connection) { $this-&gt;connection = $connection; } public function render() { $tags = $this-&gt;connection-&gt;query("SELECT * FROM tags ORDER BY name"); $tags-&gt;setFetchMode(PDO::FETCH_CLASS, "Tag"); include __DIR__ . "/TagCloudWidget.html.php"; } } // TagCloudWidget.html.php &lt;div class="tag-cloud"&gt; &lt;?php foreach ($tags as $tag) { ?&gt; &lt;span class="tag" style="font-size: &lt;?php echo $tag-&gt;importance; ?&gt;px;"&gt;&lt;?php echo $tag-&gt;name; ?&gt;&lt;/span&gt; &lt;?php } ?&gt; &lt;/div&gt; </code></pre> <p>What is the best way how to do it in Symfony? How to make the widget's dependecies to be managed by DI container?</p>