User Tools

Site Tools


symfony:symfony_tutorial_notes:creating_and_using_templates

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
symfony:symfony_tutorial_notes:creating_and_using_templates [2015/09/16 21:28] – [Debugging] mithatsymfony:symfony_tutorial_notes:creating_and_using_templates [2015/09/16 21:40] – [Including other Templates] mithat
Line 3: Line 3:
 ===== TL;DR ===== ===== TL;DR =====
   * Templates typically live in ''app/Resources/views/''.   * Templates typically live in ''app/Resources/views/''.
-  * Third-party bundle templates live in ''path/to/bundle/Resources/views/''. (Command line generator puts them here too it seems; also seems not a best practice.)+  * Third-party bundle templates live in ''path/to/bundle/Resources/views/''. (The command line generator puts them here too it seems, which I believe is no longer a best practice.)
  
 <code twig> <code twig>
Line 47: Line 47:
 ==== Including other Templates ==== ==== Including other Templates ====
 <code twig> <code twig>
-    {% for article in articles %} +{% for article in articles %} 
-        {{ include('article/article_details.html.twig', { 'article': article }) }} +    {{ include('article/article_details.html.twig', { 'article': article }) }} 
-    {% endfor %}+{% endfor %}
 </code> </code>
  
Line 152: Line 152:
  
 ===== Configuring and Using the templating Service ===== ===== Configuring and Using the templating Service =====
-TODO+<code php> 
 +return $this->render('article/index.html.twig'); 
 +</code>
  
 +is equivalent to:
 +
 +<code php>
 +use Symfony\Component\HttpFoundation\Response;
 +
 +$engine = $this->container->get('templating');
 +$content = $engine->render('article/index.html.twig');
 +
 +return $response = new Response($content);
 +</code>
 +
 +It's preconfigured out of the box. Further config is in:
 +
 +<file yaml app/config/config.yml>
 +framework:
 +    # ...
 +    templating: { engines: ['twig'] }
 +</file>
 ===== Overriding Bundle Templates ===== ===== Overriding Bundle Templates =====
-TODO+[[http://symfony.com/doc/current/book/templating.html#overriding-bundle-templates|The source]].
  
 ==== Overriding Core Templates ==== ==== Overriding Core Templates ====
-TODO+[[http://symfony.com/doc/current/book/templating.html#overriding-core-templates|The source]].
  
 ===== Three-level Inheritance ===== ===== Three-level Inheritance =====
symfony/symfony_tutorial_notes/creating_and_using_templates.txt · Last modified: 2015/09/16 21:41 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki