KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am creating an online store. I have a performance problem if I use the twig function "render" instead of "include". Here is the code that displays a product catalog: catalog controller: <?php // src/Acme/StoreBundle/Controller/Product/Catalog.php namespace Acme\StoreBundle\Controller\Product; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; class CatalogController extends Controller { /** * @Template() */ public function productAction(\Acme\StoreBundle\Entity\Product\Category $category) { $qb = $this->getDoctrine() ->getRepository('StoreBundle:Product') ->createQueryBuilder('product') ->select('partial product.{id, token, name}') ->innerJoin('product.categoryRelation', 'categoryRelation') ->where('categoryRelation.category = :category_id'); $qb->setParameters(array( 'category_id' => $category->getId(), )); $products = $qb->getQuery() ->getResult(); return $this->render('StoreBundle:Product\Catalog:product.html.twig', array( 'category' => $category, 'products' => $products, )); } } ... template for catalog controller: {# src/Acme/StoreBundle/Resources/views/Product/Catalog/product.html.twig #} {% extends 'AcmeDemoBundle::layout.html.twig' %} {% block content %} <h1>{{ category.name }}</h1> <ul> {% for product in products %} <li> {#% render "StoreBundle:Product:show" with { product: product } %#} {% include "StoreBundle:Product:show.html.twig" with { product: product } %} </li> {% endfor %} </ul> {% endblock %} ... product controller: <?php // src/Acme/StoreBundle/
Tags (comma-separated)
Save Edits
Cancel