<?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>Twig | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/category/php/twig/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Thu, 25 Aug 2022 09:55:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Twig Extension for Money value object</title>
		<link>https://nerdpress.org/2016/03/12/twig-extension-for-money-value-object/</link>
					<comments>https://nerdpress.org/2016/03/12/twig-extension-for-money-value-object/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Sat, 12 Mar 2016 14:29:53 +0000</pubDate>
				<category><![CDATA[Twig]]></category>
		<category><![CDATA[Twig Extension]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2672</guid>

					<description><![CDATA[<p>Update!!sebastianbergmann/money was abbandonend and the extension was ported to use https://github.com/moneyphp/money instead. I just released a twig extension for https://github.com/sebastianbergmann/money The money libary contains a money represention based on the currency&#8217;s smallest unit to provide a more accurate handling. See the libary&#8217;s readme for more information. Although the v1.x version of Money brings a Formatter &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2016/03/12/twig-extension-for-money-value-object/" class="more-link">Continue reading<span class="screen-reader-text"> "Twig Extension for Money value object"</span></a></p>
The post <a href="https://nerdpress.org/2016/03/12/twig-extension-for-money-value-object/">Twig Extension for Money value object</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p><strong>Update!!</strong><br /><a href="https://github.com/sebastianbergmann/money">sebastianbergmann/money</a> was abbandonend and the extension was ported to use <a href="https://github.com/moneyphp/money">https://github.com/moneyphp/money</a> instead. </p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p>I just released a <a href="https://github.com/ivoba/money-twig-extension">twig extension</a> for <a href="https://github.com/sebastianbergmann/money">https://github.com/sebastianbergmann/money</a></p>



<p>The money libary contains a money represention based on the currency&#8217;s smallest unit to provide a more accurate handling. See the libary&#8217;s readme for more information.</p>



<p>Although the v1.x version of Money brings a Formatter the Twig extension uses its own, which is better suited and more flexible.</p>



<span id="more-2672"></span>



<p>What it does? See this:</p>



<pre class="wp-block-preformatted"><pre class="brush: plain; title: ; notranslate">
{{ money|money_i18n_format('de_DE') }} 1.123,45 €
{{ money|money_i18n_format('en_US') }} €1,123.45
{{ money|money_i18n_decimal('en_US') }} 1,123.45
{{ money|money_currency_symbol('en_US') }} €
{{ money|money_currency_name('en_US') }} Euro
</pre></pre>



<p>Check the <a href="https://github.com/ivoba/money-twig-extension">readme</a> for more information.</p>The post <a href="https://nerdpress.org/2016/03/12/twig-extension-for-money-value-object/">Twig Extension for Money value object</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2016/03/12/twig-extension-for-money-value-object/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Enable Twig-Extensions in Silex revisited</title>
		<link>https://nerdpress.org/2014/05/05/enable-twig-extensions-silex-revisited/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 05 May 2014 16:20:51 +0000</pubDate>
				<category><![CDATA[Silex]]></category>
		<category><![CDATA[Twig]]></category>
		<category><![CDATA[silex]]></category>
		<category><![CDATA[Twig Extension]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2545</guid>

					<description><![CDATA[<p>As of 2014 things have changed improved a lot in the Symfony / Silex world, compared to 2011, when i first blogged about twig extensions in Silex. Things got more easy, yay! As Composer appeared, installation and autoloading is a breeze nowadays. I presume here, that you have installed your Silex project via composer. If &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2014/05/05/enable-twig-extensions-silex-revisited/" class="more-link">Continue reading<span class="screen-reader-text"> "Enable Twig-Extensions in Silex revisited"</span></a></p>
The post <a href="https://nerdpress.org/2014/05/05/enable-twig-extensions-silex-revisited/">Enable Twig-Extensions in Silex revisited</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>As of 2014 things have <del datetime="2014-05-05T16:12:03+00:00">changed</del> improved a lot in the Symfony / Silex world, compared to 2011, when <a href="https://nerdpress.org/2011/11/21/enable-twig-extensions-in-silex/">i first blogged about twig extensions in Silex</a>.<br />
Things got more easy, yay!</p>
<p>As Composer appeared, installation and autoloading is a breeze nowadays.<br />
I presume here, that you have installed your Silex project via composer.<br />
If so, you can install the twig extensions like this:<br />
<span id="more-2545"></span><br />
Just go to your project folder and run:</p>
<pre class="brush: plain; title: ; notranslate">composer require twig/extensions:~1.0</pre>
<p>and your done with installation and autoloading.</p>
<p>Now to integration and service registration, this also got more easy.</p>
<p>Place this after you have registered the twig service:</p>
<pre class="brush: php; title: ; notranslate">$app&#x5B;'twig'] = $app-&gt;share($app-&gt;extend('twig', function($twig, $app) {
    $twig-&gt;addExtension(new Twig_Extensions_Extension_Text($app));
    return $twig;
}));</pre>
<p>Thats it, now you can use the text filters in your twig templates:</p>
<pre class="brush: plain; title: ; notranslate">
{{ post.content|truncate(200)|raw }}</pre>
<p>Easy&#8230;</p>The post <a href="https://nerdpress.org/2014/05/05/enable-twig-extensions-silex-revisited/">Enable Twig-Extensions in Silex revisited</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[Symfony 2] composer.json for a assumed-stable symfony 2 distribution</title>
		<link>https://nerdpress.org/2012/04/01/symfony-2-composer-json-for-a-assumed-stable-symfony-2-distribution/</link>
					<comments>https://nerdpress.org/2012/04/01/symfony-2-composer-json-for-a-assumed-stable-symfony-2-distribution/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 01 Apr 2012 12:18:54 +0000</pubDate>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Project Setup]]></category>
		<category><![CDATA[Silex]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Twig]]></category>
		<category><![CDATA[composer.phar]]></category>
		<category><![CDATA[dependency management]]></category>
		<category><![CDATA[packagist]]></category>
		<category><![CDATA[symfony 2]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2118</guid>

					<description><![CDATA[<p>This small composer.json file is used in a project i am working on atm, feel free to use it at own risk. I will provide non-periodical updates and hopefully soon a full upgrade to symfony 2.1.x including doctrine orm 2.2.x. I still did not get the point regarding dependency resolution, so i simply &#8220;composed&#8221; the &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2012/04/01/symfony-2-composer-json-for-a-assumed-stable-symfony-2-distribution/" class="more-link">Continue reading<span class="screen-reader-text"> "[Symfony 2] composer.json for a assumed-stable symfony 2 distribution"</span></a></p>
The post <a href="https://nerdpress.org/2012/04/01/symfony-2-composer-json-for-a-assumed-stable-symfony-2-distribution/">[Symfony 2] composer.json for a assumed-stable symfony 2 distribution</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>This small composer.json file is used in a project i am working on atm, feel free to use it at own risk. I will provide non-periodical updates and hopefully soon a full upgrade to symfony 2.1.x including doctrine orm 2.2.x.</p>
<p>I still did not get the point regarding dependency resolution, so i simply &#8220;composed&#8221; the composer file by writing down my own requirements (&#8220;i want only the hottest, newest stuff!!&#8221;, then tracked down the error messages, removing them by explicetly writing down the missing dependencies by using the latest &#8220;dev-*&#8221; versions. After that i tried to run the project, which actually did not work, but selective downgrade of some of the bundles (framework, security-extra blahblah) finally did the job.<span id="more-2118"></span></p>
<p>Feel free to use it in your own projects:</p>
<pre class="brush: jscript; title: ; notranslate">
{
	&quot;require&quot; : {
              &quot;symfony/symfony&quot; : &quot;v2.0.12&quot;,
              &quot;doctrine/common&quot; : &quot;2.1.4&quot;,
              &quot;doctrine/orm&quot; : &quot;2.1.6&quot;,
              &quot;symfony/finder&quot; : &quot;v2.0.12&quot;,

              &quot;symfony/assetic-bundle&quot; : &quot;2.0-dev&quot;,
              &quot;twig/extensions&quot; : &quot;dev-master&quot;,
              &quot;jms/security-extra-bundle&quot; : &quot;1.1.0&quot;,
              &quot;sensio/framework-extra-bundle&quot; : &quot;2.0-dev&quot;,
              &quot;sensio/distribution-bundle&quot; : &quot;2.0-dev&quot;,
              &quot;sensio/generator-bundle&quot; : &quot;2.0-dev&quot;

 	},
        &quot;autoload&quot; : {
            &quot;psr-0&quot; : {
                &quot;Acme&quot; : &quot;src/&quot;,
            }
        }
}

</pre>
<p>Create a file named &#8220;composer.json&#8221; in your project&#8217;s root directory, then paste the above code into it and save it.</p>
<p>Now run</p>
<pre class="brush: bash; title: ; notranslate">
$ curl -s http://getcomposer.org/installer | php
</pre>
<p>After that, download all dependencies by typing</p>
<pre class="brush: bash; title: ; notranslate">
$ php composer.phar install
</pre>
<p>The easiest way to create a full project including AcmeDemoBundle, AppKernel and the whole stuff is to download the symfony 2 standard distribution without vendors and calling the script from there. The only thing to do is to modify the path to autoload.php, which should point to vendor/.composer/autoload.php.</p>
<p>Now you are able to upgrade your project&#8217;s dependencies to the newest versions by simply modifying the composer.json file. Have fun!.</p>The post <a href="https://nerdpress.org/2012/04/01/symfony-2-composer-json-for-a-assumed-stable-symfony-2-distribution/">[Symfony 2] composer.json for a assumed-stable symfony 2 distribution</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2012/04/01/symfony-2-composer-json-for-a-assumed-stable-symfony-2-distribution/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>modulo in Twig</title>
		<link>https://nerdpress.org/2012/02/14/modulo-in-twig/</link>
					<comments>https://nerdpress.org/2012/02/14/modulo-in-twig/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Tue, 14 Feb 2012 16:05:48 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Twig]]></category>
		<category><![CDATA[symfony 2]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2078</guid>

					<description><![CDATA[<p>Ever wondered how to use the modulo operator in twig, the template engine of symfony? Actually its like in PHP: {{ 11 % 7 }} As described here But i guess for most use cases modulus is used to check if a number is divisible by another number. Therefore Twig has the very conveniant divisible &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2012/02/14/modulo-in-twig/" class="more-link">Continue reading<span class="screen-reader-text"> "modulo in Twig"</span></a></p>
The post <a href="https://nerdpress.org/2012/02/14/modulo-in-twig/">modulo in Twig</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Ever wondered how to use the <strong>modulo</strong> operator in twig, the template engine of symfony?</p>
<p>Actually its like in PHP:</p>
<pre class="brush: php; title: ; notranslate">{{ 11 % 7 }}</pre>
<p>As described <a href="http://twig.sensiolabs.org/doc/templates.html#math">here</a></p>
<p>But i guess for most use cases <strong>modulus</strong> is used to check if a number is divisible by another number.<br />
Therefore Twig has the very conveniant <a href="http://twig.sensiolabs.org/doc/tests/divisibleby.html">divisible by</a> test function.</p>
<pre class="brush: php; title: ; notranslate">{% if loop.index is divisible by(3) %}</pre>
<p><span id="more-2078"></span><br />
Another modulo use case is to check odd and even rows in loops. There Twig has the built-in function <a href="http://twig.sensiolabs.org/doc/functions/cycle.html">cycle</a> to help you.</p>
<pre class="brush: php; title: ; notranslate">{{ cycle(&#x5B;'odd', 'even'], i) }}</pre>
<p>Once you know its so eeasy;)</p>The post <a href="https://nerdpress.org/2012/02/14/modulo-in-twig/">modulo in Twig</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2012/02/14/modulo-in-twig/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
