Skip to content

Instantly share code, notes, and snippets.

@serapheem
Created November 6, 2012 10:32
Show Gist options
  • Save serapheem/4023925 to your computer and use it in GitHub Desktop.
Save serapheem/4023925 to your computer and use it in GitHub Desktop.
Symfony2 - Include template inside another template
Twig:
{# src/Acme/ArticleBundle/Resources/Article/list.html.twig #}
{% extends 'AcmeArticleBundle::layout.html.twig' %}
{% block body %}
<h1>Recent Articles<h1>
{% for article in articles %}
{% include 'AcmeArticleBundle:Article:articleDetails.html.twig' with {'article': article} %}
{% endfor %}
{% endblock %}
PHP:
<!-- src/Acme/ArticleBundle/Resources/Article/list.html.php -->
<?php $view->extend('AcmeArticleBundle::layout.html.php') ?>
<?php $view['slots']->start('body') ?>
<h1>Recent Articles</h1>
<?php foreach ($articles as $article): ?>
<?php echo $view->render('AcmeArticleBundle:Article:articleDetails.html.php', array('article' => $article)) ?>
<?php endforeach; ?>
<?php $view['slots']->stop() ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment