twig
play

- Twig - PowerPoint PPT Presentation

- Twig View )


  1. هاگشنادص یتعن فیرش یسدنهم هدکشناد رتویپماک یسانشراک سرد راهب۱۳۹۱ - ۹۲ تمسق۸ Twig بلاق روتوم

  2. ربراک اب طابترا ربراک تامادقا تفایرد View ) ربراک هب تاعلبطا شیامن( Template )شیامن بلاق( Place Holders ) ،یلاخ یاهاجاه هرفح ( Hello Mohammad! Welcome to Web Programming ’s class 2

  3. Twig Template Engine کی Symfony2 کیتنناپماک زا Hello {{ name }} ! Welcome to {{ course }} ’s class ["name" => "Mohammad", "course" => "Web Programming"] 3

  4. تارابع Context {{ name }} اهریغتم {{ person.name }} اه هیارآ وءایشا {{ person*‘name’+ }} {{ attribute(person, ‘last - name’) }} {{ now - then }} {% set then=1391 %} 4

  5. اهرتلیف {{ name|title }} {{ name|upper }} {{ names|join (“, ”) }} {% filter upper }} {% endfilter %} 5

  6. یلرتنک تاروتسد <ul> {% for person in persons %} <li>{{ person.name|e }}</li> {% endfor %} </ul> {% if person .name|length > 0 %} {% endif %} 6

  7. عباوت {% for i in range(0, 3) %} {{ i }} : {{ names[i] }}, {% endfor %} range(low=1, high=10, step=2) {{ "now"|date(timezone="Europe/Paris") }} 7

  8. Composer ریدماه یگتسباو composer.json { "require": { "twig/twig": "1.*" } } > composer install 8

  9. Composer Auto Loading require_once ('vendor/autoload.php'); Loader Environment $loader = new Twig_Loader_String(); $twig = new Twig_Environment($loader); $result = $twig->render($template, $data); 9

  10. Loader عاونا $loader = new Twig_Loader_Filesystem ('/path/to/templates'); $twig = new Twig_Environment ($loader, [ 'cache' => '/path/to/compilation_cache']); 10

  11. Loader عاونا $loader = new Twig_Loader_Array([ 'index.html' => 'Hello {{ name }}!‘ ]); $twig = new Twig_Environment($loader); $twig->render('index.html', [ 'name' => ‘Mohammad‘ ]); 11

  12. Extension اه رتلیف تاروتسد Loader ... Extensio هدامآ یاه Escaper Optimizer 12

  13. {{ user.username|raw }} {{ user.username|e}} {{ user.username|e('js') }} {{ user.username|e('css') }} {{ user.username|e('url') }} {{ user.username|e('html_attr') }} {% autoscape 'js' %} {% endautoscape %} 13

  14. include <div id="sidebar"> {% include 'sidebar.html' %} </div> Context ندرب ثرا هب {% for post in posts %} {% include "post_box.html" %} {% endfor %} 14

  15. base.html: تثارو <head> Skeleton {% block head %} Blocks {% endblock %} Overriding </head> page.html : {{ parent() }} {% extends ‘base.html ' %} {% block head %} <script ...></script> 15 {% endblock %}

  16. Symfony Book, 2.2. http://twig.sensiolabs.org/documentation 16

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend