<?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>Agence de Développement Informatique du Nord &#187; twig</title>
	<atom:link href="http://blog.adin.pro/tag/twig/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.adin.pro</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 26 Dec 2019 08:54:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>Symfony2 sonata custom CRUD template</title>
		<link>http://blog.adin.pro/2013-10-07/symfony2-sonata-custom-crud-template/</link>
		<comments>http://blog.adin.pro/2013-10-07/symfony2-sonata-custom-crud-template/#comments</comments>
		<pubDate>Mon, 07 Oct 2013 14:10:57 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Sonata]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Twig]]></category>
		<category><![CDATA[Override]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[twig]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=306</guid>
		<description><![CDATA[<p>It is possible to change templates use by default. First, override the controller action method, in your AdminBundle/Controller/SecteurAdminController.php file The import thing on previous code is the render() fonction, the first parameter is the template to use. In our example, &#8230; <a href="http://blog.adin.pro/2013-10-07/symfony2-sonata-custom-crud-template/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-07/symfony2-sonata-custom-crud-template/">Symfony2 sonata custom CRUD template</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>It is possible to change templates use by default.</p>
<p>First, override the controller action method, in your AdminBundle/Controller/SecteurAdminController.php file</p>
<pre class="brush: php; title: ; notranslate">
 /**
     * return the Response object associated to the list action
     *
     * @return Response
     */
    public function listAction()
    {
        if (false === $this-&gt;admin-&gt;isGranted('LIST')) {
            throw new AccessDeniedException();
        }

        $datagrid = $this-&gt;admin-&gt;getDatagrid();
        $formView = $datagrid-&gt;getForm()-&gt;createView();

        // set the theme for the current Admin Form
        $this-&gt;get('twig')-&gt;getExtension('form')-&gt;setTheme($formView, $this-&gt;admin-&gt;getFilterTheme());

        //custom code from here
        $total = 0;
        $enable = 0;
        $new = 0;
        $site = $this-&gt;admin-&gt;site;

        $repository = $this-&gt;getDoctrine()-&gt;getRepository('TripixAdminBundle:Annonce');
        $total = $repository-&gt;getNombreAnnonceTotal($site);
        $enable = $repository-&gt;getNombreAnnonceEnabled($site);
        $new = $repository-&gt;getNombreAnnonceNew($site);



        return $this-&gt;render('TripixAdminBundle:CRUD:list_secteur.html.twig', array(
            'action'   =&gt; 'list',
            'form'     =&gt; $formView,
            'datagrid' =&gt; $datagrid,
            'total'     =&gt; $total,
            'enable'    =&gt; $enable,
            'new'       =&gt; $new,
        ));
    }
</pre>
<p>The import thing on previous code is the render() fonction, the first parameter is the template to use.<br />
In our example, the template file will be /AdminBundle/Ressources/view/CRUD/list_secteur.html.twig</p>
<p>You can use the /AdminBundle/Ressources/view/CRUD/base_secteur.html.twig file as example for your custom template.</p>
<p>Parent function to override on the controller are here : /vendor/bundles/Sonata/AdminBundle/Controller/CRUDController.php</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-07/symfony2-sonata-custom-crud-template/">Symfony2 sonata custom CRUD template</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-10-07/symfony2-sonata-custom-crud-template/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony2 Sonata add custom column on page list</title>
		<link>http://blog.adin.pro/2013-10-07/symfony2-sonata-add-custom-column-on-page-list/</link>
		<comments>http://blog.adin.pro/2013-10-07/symfony2-sonata-add-custom-column-on-page-list/#comments</comments>
		<pubDate>Mon, 07 Oct 2013 12:44:16 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Sonata]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[twig]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=302</guid>
		<description><![CDATA[<p>To add a custom column on a page list, just follow these steps. In the example, we will add a &#8220;Nombre d&#8217;annoce(s)&#8221; column. On your admin class file (ex: /AdminBundle/Admin/SecteurAdmin.php), on your configureListFields() fonction, add a new entry on the &#8230; <a href="http://blog.adin.pro/2013-10-07/symfony2-sonata-add-custom-column-on-page-list/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-07/symfony2-sonata-add-custom-column-on-page-list/">Symfony2 Sonata add custom column on page list</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>To add a custom column on a page list, just follow these steps. In the example, we will add a &#8220;Nombre d&#8217;annoce(s)&#8221; column.</p>
<p>On your admin class file (ex: /AdminBundle/Admin/SecteurAdmin.php), on your configureListFields() fonction, add a new entry on the listMapper object</p>
<pre class="brush: php; title: ; notranslate">
    /**
     * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
     * @return void
     */
    protected function configureListFields(ListMapper $listMapper) {
        $listMapper
                -&gt;addIdentifier('titre')
                -&gt;add('Tri', 'string', array('template' =&gt; 'TripixAdminBundle:Admin:list_tri.html.twig'))
                -&gt;add('Nb', 'string', array('label' =&gt; 'Nombre d\'annonce(s)', 'template' =&gt; 'TripixAdminBundle:Admin:list_nb_annonce.html.twig'))
                -&gt;add('_action', 'actions', array(
                    'actions' =&gt; array(
                        'edit' =&gt; array(),
                        'delete' =&gt; array(),
                    )
                ))
        ;
    }
</pre>
<p>This new entry said to use the TripixADminBundle:Admin:list_tri.html.twig template.</p>
<p>Now, create your template file (list_nb_annonce.html) in the /AdminBundle/ressources/view/admin/ directory.</p>
<pre class="brush: php; title: ; notranslate">
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}

{% block field%}
{% if admin.datagrid.results|length &gt; 1 %}
 &lt;div&gt;
        &lt;strong&gt;{{ object.getNombreAnnonce}}&lt;/strong&gt;
    &lt;/div&gt;
{% endif %}
{% endblock %}
</pre>
<p>In our example, getNombreAnnonce() is not defined, let&#8217;s do it<br />
In the /adminBundle/Entity/Secteur.php file, add</p>
<pre class="brush: php; title: ; notranslate">
   public function getNombreAnnonce()
    {
      return count($this-&gt;getAnnonces());
    }
</pre>
<p>That&#8217;s all.</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-07/symfony2-sonata-add-custom-column-on-page-list/">Symfony2 Sonata add custom column on page list</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-10-07/symfony2-sonata-add-custom-column-on-page-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony2 twig add new function file_exists</title>
		<link>http://blog.adin.pro/2013-05-10/symfony2-twig-add-new-function-file_exists/</link>
		<comments>http://blog.adin.pro/2013-05-10/symfony2-twig-add-new-function-file_exists/#comments</comments>
		<pubDate>Fri, 10 May 2013 07:43:52 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Twig]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[twig]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=184</guid>
		<description><![CDATA[<p>An important function is missing on twig : file_exists. I will show you here how to define a new function for twig. On your namespace/bundle, add a Twig/Extension directory and create your class file : /src/Adin/ArlogisBundle/Twig/Extension/FileExistsExtension.php You then have to &#8230; <a href="http://blog.adin.pro/2013-05-10/symfony2-twig-add-new-function-file_exists/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-05-10/symfony2-twig-add-new-function-file_exists/">Symfony2 twig add new function file_exists</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>An important function is missing on twig : file_exists.</p>
<p>I will show you here how to define a new function for twig.</p>
<p>On your namespace/bundle, add a Twig/Extension directory and create your class file :<br />
/src/Adin/ArlogisBundle/Twig/Extension/FileExistsExtension.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace Adin\ArlogisBundle\Twig\Extension;

class FileExistsExtension extends \twig_Extension
{
        /**
         *Return the function registered as twig extension
         *
         *@return array
         */
        public function getFunctions()
        {
                return array(
                        'file_exists' =&gt; new \Twig_Function_Function('file_exists'),
                        );
        }

        public function getName()
        {
                return 'adin_file_exists';
        }
}
?&gt;
</pre>
<p>You then have to register your service, add a <service> in your /Adin/ArlogisBundle/Ressources/config/services.xml file</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; ?&gt;

&lt;container xmlns=&quot;http://symfony.com/schema/dic/services&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xsi:schemaLocation=&quot;http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd&quot;&gt;
&lt;services&gt;
       &lt;service id=&quot;adin.twig.tripix_extension&quot; class=&quot;Adin\ArlogisBundle\Twig\Extension\FileExistsExtension&quot;&gt;
        &lt;tag name=&quot;twig.extension&quot; /&gt;
        &lt;/service&gt;
    &lt;/services&gt;
&lt;/container&gt;
</pre>
<p>It&#8217;s ready, you can use it on your twig template</p>
<pre class="brush: php; title: ; notranslate">
{% if file_exists('/var/www/image.jpg') %}
    File exists
{% else %}
    File not exists
{% endif %}
</pre>
<p>Be carefull, you need to specify the absolute path of the file. You can create a twig global variable root_path.<br />
app/config/config.yml</p>
<pre class="brush: php; title: ; notranslate">
# Twig Configuration
twig:
    globals:
        root_path: %kernel.root_dir%/../web
</pre>
<p>Then on twig template</p>
<pre class="brush: php; title: ; notranslate">
{% if file_exists({{root_path}}'/var/www/image.jpg') %}
    File exists
{% else %}
    File not exists
{% endif %}
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-05-10/symfony2-twig-add-new-function-file_exists/">Symfony2 twig add new function file_exists</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-05-10/symfony2-twig-add-new-function-file_exists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Fatal error:  Method Gregwar\\ImageBundle\\ImageHandler::__toString() must not throw an exception in /home/www/recette/app/cache/dev/classes.php on line 7426</title>
		<link>http://blog.adin.pro/2013-03-21/php-fatal-error-method-gregwarimagebundleimagehandler__tostring-must-not-throw-an-exception-in-homewwwrecetteappcachedevclasses-php-on-line-7426/</link>
		<comments>http://blog.adin.pro/2013-03-21/php-fatal-error-method-gregwarimagebundleimagehandler__tostring-must-not-throw-an-exception-in-homewwwrecetteappcachedevclasses-php-on-line-7426/#comments</comments>
		<pubDate>Thu, 21 Mar 2013 09:03:13 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[gregwar]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[twig]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=149</guid>
		<description><![CDATA[<p>You are using the fanstactic Gregwar/ImageBundle code to manipulate your images on Symfony2 and twig. But instead of rendering your website, you get this error on your apache error log file or directly on your html genered code this issue &#8230; <a href="http://blog.adin.pro/2013-03-21/php-fatal-error-method-gregwarimagebundleimagehandler__tostring-must-not-throw-an-exception-in-homewwwrecetteappcachedevclasses-php-on-line-7426/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-03-21/php-fatal-error-method-gregwarimagebundleimagehandler__tostring-must-not-throw-an-exception-in-homewwwrecetteappcachedevclasses-php-on-line-7426/">PHP Fatal error:  Method Gregwar\\ImageBundle\\ImageHandler::__toString() must not throw an exception in /home/www/recette/app/cache/dev/classes.php on line 7426</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You are using the fanstactic Gregwar/ImageBundle code to manipulate your images on Symfony2 and twig.<br />
But instead of rendering your website, you get this error on your apache error log file </p>
<pre class="brush: bash; title: ; notranslate">
PHP Fatal error:  Method Gregwar\\ImageBundle\\ImageHandler::__toString() must not throw an exception in /home/www/recette/app/cache/dev/classes.php on line 7426
</pre>
<p>or directly on your html genered code</p>
<pre class="brush: xml; title: ; notranslate">
&lt;img src=&quot;
Fatal error: Method Gregwar\ImageBundle\ImageHandler::__toString() must not throw an exception in /home/www/recette/app/cache/dev/classes.php on line 7426
</pre>
<p>this issue may be a rights problem on your cache drectory. By default, gregwar cache directory is on your web so, launch this command</p>
<pre class="brush: bash; title: ; notranslate">
chmod 777 web/cache
</pre>
<p>This error may also occur if the file doesn&#8217;t exist, for a clean code, add</p>
<pre class="brush: php; title: ; notranslate">
{% if file_exists('uploads/' ~ site.id ~ '.jpg') %}
    {{ image(site.picture).resize(250, 50) }}
{% endif %}
</pre>
<p>or on twig code</p>
<pre class="brush: php; title: ; notranslate">
{% if site.has_picture %}
    {{ image(site.picture).resize(250 ,50) }}
{% endif %}
</pre>
<p>For more informations about file_exists, see here <a href="http://blog.adin.pro/2013-05-10/symfony2-twig-add-new-function-file_exists/" title="Symfony2 twig add new function file_exists">Symfony2 twig add new function file_exists</a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-03-21/php-fatal-error-method-gregwarimagebundleimagehandler__tostring-must-not-throw-an-exception-in-homewwwrecetteappcachedevclasses-php-on-line-7426/">PHP Fatal error:  Method Gregwar\\ImageBundle\\ImageHandler::__toString() must not throw an exception in /home/www/recette/app/cache/dev/classes.php on line 7426</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-03-21/php-fatal-error-method-gregwarimagebundleimagehandler__tostring-must-not-throw-an-exception-in-homewwwrecetteappcachedevclasses-php-on-line-7426/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
