<?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/category/twig-2/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 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>
	</channel>
</rss>
