<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NemoPS &#187; symfony</title>
	<atom:link href="http://nemops.com/tag/symfony/feed/" rel="self" type="application/rss+xml" />
	<link>http://nemops.com</link>
	<description>Prestashop Tutorials, Modules and More!</description>
	<lastBuildDate>Wed, 05 Dec 2018 13:25:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.35</generator>
	<item>
		<title>Prestashop 1.7, Symfony and Twig</title>
		<link>http://nemops.com/prestashop-1-7-symfony-twig/</link>
		<comments>http://nemops.com/prestashop-1-7-symfony-twig/#comments</comments>
		<pubDate>Mon, 07 Dec 2015 11:24:51 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[prestashop 1.7]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[twig]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2664</guid>
		<description><![CDATA[<p>Prestashop 1.7 will introduce the PHP framework Symfony, since the very first version. What will this mean, for developers? Prestashop 1.7 code changes summary PrestaShop 1.7 will introduce a brand new architecture, based on the Symfony Framework, along with its Twig templating engine. The new architecture will only be used in the back office for [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-1-7-symfony-twig/">Prestashop 1.7, Symfony and Twig</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Prestashop 1.7 will introduce the PHP framework Symfony, since the very first version. What will this mean, for developers?<br />
<span id="more-2664"></span></p>
<h2>Prestashop 1.7 code changes summary</h2>
<ul>
<li>PrestaShop 1.7 will introduce a brand new architecture, based on the Symfony Framework, along with its Twig templating engine.</li>
<li>The new architecture will only be used in the back office for now, and at first (1.7) only for two pages of the back office: the Product page and the Modules page.</li>
<li>The rest of the back office will still use the legacy architecture from 1.5-1.6 – but they will be switched to the new architecture in later versions of PrestaShop</li>
<li>The two architectures will coexist while we switch more back office pages to the new architecture, in a transition phase that will take a few versions of PrestaShop.</li>
<li>Only modules that target the Product and Modules pages will need to see their templating code adapted.</li>
</ul>
<p><small>This is coming directly from the official <a target="_blank" href="http://build.prestashop.com/news/prestashop-1-7-and-symfony/" title="PrestaShop Development Blog">PrestaShop Development Blog</a></small>.</p>
<div class="separator"></div>
<h2>Whichs part of PrestaShop will be rewritten using Symfony?</h2>
<p>The official blog itself states that <strong>PrestaShop 1.7 will not be 100% written in Symfony </strong>. Apparently, only part of the back office, namely the Product and the Modules pages, will be affected. The rest will be left untouched, meaning everything will still be based on the old Object Model / Hooks architecture.<br />
They are obviously planning to expand the usage to cover more pages, little by little, with every new version.</p>
<p>As you probably know, PrestaShop is currently using <a target="_blank" href="http://www.smarty.net/" title="Smarty Template Engine">Smarty</a> as template engine for both the front and back office. This is not going to happen on pages using Symfony. Instead, they will use its own template engine, named <strong><a target="_blank" href="http://twig.sensiolabs.org/" title="Twig Template Engine">Twig</a></strong>. I am not the biggest fan of Twig, but I guess we will have to deal with it.</p>
<p>The front office will not use Symfony, however, <strong>1.6 themes will not, by any mean, be compatible with 1.7.</strong></p>
<div class="separator"></div>
<h2>A good news for Modules Developer</h2>
<p>The only modules that are going to be affected by this change are the ones hooking to the Product or Module back office. No fear though, we will not have to change anything of our modules since day 1. Instead, the PrestaShop team is setting up a switch that <strong>will let users run modules in legacy mode if they have not been rewritten in Twig.</strong></p>
<p>Notice I am referring to Twig, and not Symfony, because the display part only would be affected. <strong>We will not be required to change anything of the PHP codebase</strong>, at least not at the beginning.</p>
<div class="separator"></div>
<h2>Symfony2 and Twig</h2>
<p><a href="http://nemops.com/wp-content/uploads/2015/12/symfony.jpg"><img src="http://nemops.com/wp-content/uploads/2015/12/symfony-680x189.jpg" alt="Symfony PHP Framework" width="680" height="189" class="aligncenter size-large wp-image-2666" /></a></p>
<p>What are these, exactly? For the ones who have never heard it, Symfony is a PHP framework (like Zend, Laravel, or CodeIgniter). As such, it provides several helpers and components to make our life easier when coding anything in PHP.</p>
<p>The Team&#8217;s decision to choose version 2 if however arguable: <a target="_blank" href="https://symfony.com/roadmap">Symfony 3.0 has been released last november,</a> and this means PrestaShop&#8217;s &#8220;new&#8221; core architecture will be outdated before even having seen the light. I strongly hope they will drop Symfony2 in favor of version 3 as soon as they can.</p>
<p><a href="http://nemops.com/wp-content/uploads/2015/12/twig.jpg"><img src="http://nemops.com/wp-content/uploads/2015/12/twig.jpg" alt="Twig - Template Engine for Symfony" width="328" height="200" class="aligncenter size-full wp-image-2667" /></a></p>
<p>As for Twig, it&#8217;s a full-fledged template engine created by the same developers of Symfony. It&#8217;s very similar to Smarty, so, the transition shouldn&#8217;t be overly traumatic.</p>
<h3>Differences between Twig and Smarty</h3>
<p>Here are a few example of the main differences between the two engines.</p>
<h4>Variable assignment and template display</h4>
<p>Smarty in PrestaShop 1.6</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
	$this-&gt;context-&gt;smarty-&gt;assign(array('the' =&gt; 'variables', 'go' =&gt; 'here'));
	return $this-&gt;display(__FILE__, 'template.tpl');
</pre>
<p>Twig</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
	echo $twig-&gt;render('index.html', array('the' =&gt; 'variables', 'go' =&gt; 'here'));
</pre>
<h4>Variables in templates</h4>
<p>Smarty in PrestaShop 1.6</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
	{$variable.name}
</pre>
<p>Twig</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
	{{ foo.bar }}
	{{ foo['bar'] }} // both are fine, this is just an alternative
</pre>
<h4>Control structures in templates</h4>
<p>Smarty in PrestaShop 1.6</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
	
	{if ($shop_phone)}
		{l s='Tel: %s' sprintf=[$shop_phone|escape:'html':'UTF-8'] pdf='true'}
	{/if}
	{foreach from=$array item=myitem}
		&lt;p&gt;{$item}&lt;/p&gt;
	{/foreach}

</pre>
<p>Twig</p>
<pre class="brush: php; html-script: true; title: ; notranslate">
{% if users|length &gt; 0 %}
	&lt;ul&gt;
	    {% for user in users %}
	        &lt;li&gt;{{ user.username|e }}&lt;/li&gt;
	    {% endfor %}
	&lt;/ul&gt;
{% endif %}
</pre>
<div class="separator"></div>
<h2>Bottom Line</h2>
<p>We can&#8217;t tell if the transition to Symfony will bring fresh air in te PrestaShop development flow, at this stage. The team&#8217;s intentions seem serious enough though, so it&#8217;s strongly advisable to start learning Symfony and Twig as soon as you can.</p>
<ul>
<li><strong><a target="_blank" href="https://symfony.com/doc/current/index.html" title="Symfony Documentation">Symfony Documentation</a></strong></li>
<li><strong><a target="_blank" href="http://twig.sensiolabs.org/documentation" title="Twig Documentation">Twig Documentation</a></strong></li>
</ul>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-1-7-symfony-twig/">Prestashop 1.7, Symfony and Twig</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-1-7-symfony-twig/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
