twig

Zend expressive - Layout

丶灬走出姿态 提交于 2020-01-16 18:25:13
问题 In my layout (Twig), i'd like to retrieve a value from a Middleware authentication. If i put, in templates.global.pĥp: 'twig' => [ 'globals' => [ // Variables to pass to all twig templates 'auth' => (new \Zend\Authentication\AuthenticationService())->hasIdentity(), ], ], And in layout default.html.twig {% if auth %} Connect {% else %} Not connect {% endif %} This code works, but, is it a good method ? Thank you :) 回答1: It's not a good method. First of all, using the config files to set global

Symfony 2.2 => symfony 2.3 error Deutsch locale

梦想的初衷 提交于 2020-01-16 17:26:47
问题 I have just done the upgrade from 2.2 to 2.3.2 version. Into the symfony 2.2, there was no error. WHen I have upgrading to 2.3.2 version I had this error. Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("[ERROR 94] Validation failed: no DTD found ! (in n/a - line 2, column 21) [ERROR 9] Input is not proper UTF-8, indicate encoding ! Bytes: 0xFC 0x67 0x65 0x6E (in n/a - line 51, column 23)") in "MyAppBundle:Controler:index.html.twig". For your information

Symfony 2.2 => symfony 2.3 error Deutsch locale

▼魔方 西西 提交于 2020-01-16 17:26:46
问题 I have just done the upgrade from 2.2 to 2.3.2 version. Into the symfony 2.2, there was no error. WHen I have upgrading to 2.3.2 version I had this error. Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("[ERROR 94] Validation failed: no DTD found ! (in n/a - line 2, column 21) [ERROR 9] Input is not proper UTF-8, indicate encoding ! Bytes: 0xFC 0x67 0x65 0x6E (in n/a - line 51, column 23)") in "MyAppBundle:Controler:index.html.twig". For your information

Twig date filter not working with DateTime object

谁说我不能喝 提交于 2020-01-15 12:45:12
问题 I'm using CI2 with Doctrine2 and Twig for the template engine. I'm trying to display the date from an entity as a string, however it's not working for me. I'm sending an array of Entity objects to the template, iterating through them, and displaying their properties: {% for e in entities %} <span><label>username</label>{{e.getUserName}}</span> <span><label>email</label>{{e.getEmail}}</span> <span><label>date created</label>{{e.getCreatedAt | date('d.M.Y H:i:s')}}</span> {% endfor %} The

Twig date filter not working with DateTime object

天大地大妈咪最大 提交于 2020-01-15 12:45:06
问题 I'm using CI2 with Doctrine2 and Twig for the template engine. I'm trying to display the date from an entity as a string, however it's not working for me. I'm sending an array of Entity objects to the template, iterating through them, and displaying their properties: {% for e in entities %} <span><label>username</label>{{e.getUserName}}</span> <span><label>email</label>{{e.getEmail}}</span> <span><label>date created</label>{{e.getCreatedAt | date('d.M.Y H:i:s')}}</span> {% endfor %} The

How do I specify two locations for Twig templates?

五迷三道 提交于 2020-01-15 12:33:32
问题 I've structured my website with a separate directory for each component (i.e. page). /var/www/components/component_1/ /var/www/components/component_2/ /var/www/components/component_3/ Within each directory, I have a controller, a model, and a Twig template. A typical template which might be located at /var/www/components/component_2/templates/myTemp.html looks like the following: {% extends "base.html" %} bla bla bla I have several base templates. Unlike the child templates, I wish these to

How do I specify two locations for Twig templates?

自作多情 提交于 2020-01-15 12:33:24
问题 I've structured my website with a separate directory for each component (i.e. page). /var/www/components/component_1/ /var/www/components/component_2/ /var/www/components/component_3/ Within each directory, I have a controller, a model, and a Twig template. A typical template which might be located at /var/www/components/component_2/templates/myTemp.html looks like the following: {% extends "base.html" %} bla bla bla I have several base templates. Unlike the child templates, I wish these to

Custom Twig Function Not Recognized

China☆狼群 提交于 2020-01-15 08:51:30
问题 I have a twig/timber function and the code doesn't shows any error but when I go to use function in my twig template there is an error saying '' is not a function. This is what I have in my fucntions.php file in the twig template: add_filter( 'timber/twig', function( \Twig_Environment $twig ) { $twig->addFunction( new Twig_Function( 'get_custom_meta', 'get_custom_meta' ) ); } ); function get_custom_meta($key,$id){ if(empty($id)){ return types_render_field($key,array("raw"=>"true","separator"=

Reduce form groups layout in Twig with Symfony2(.7)

泪湿孤枕 提交于 2020-01-14 08:48:07
问题 I am trying to get rid of repeating layouts in twig for symfony2 forms Currently my layout looks something like : <form name="step2" method="post" action="" class="productForm"> <h2>Step2:</h2> <div id="step2"> <div class="form-group"> <div class="form-widget"> <div id="step2_client1"> <div class="form-group"><label class="control-label required" for="step2_client1_clientTitle">Client 1 title:</label> <div class="form-widget"><select id="step2_client1_clientTitle" name="step2[client1]

symfony twig translation not working after update

感情迁移 提交于 2020-01-14 05:21:07
问题 I upgraded my project from 2.5.x to 2.8.1 and suddenly twig is not using the correct translations anymore. In the twig template i have something like this: {% trans %}something.abc{% endtrans %} my config.yml looks like this: ... framework: translator: ~ ... templating: engines: ['twig'] default_locale: en_US in Controller action: $request->setLocale('nl_BE'); The page is always showing the en_US translation and never something else. Did something change? 回答1: It is because the