twig-extension

Symfony 4.1 twig extension

不想你离开。 提交于 2020-06-26 12:25:23
问题 In Symfony 4.1 I created an twig extension and I tried to use it as an service twig.extension.active.algos: class: App\Twig\AppExtension public: true tags: - { name: twig.extension, priority: 1024 } Unfortunately I receive 'Unable to register extension "App\Twig\AppExtension" as it is already registered' After many searches I saw that there was a bag in the version of symfony 3.4 but they say the error would have solved. So it's my mistake or just another mistake from symfony team. My

Register Twig Extension in Symfony

假装没事ソ 提交于 2020-06-23 05:07:06
问题 I want to use nochso/html-compress-twig extension to compress all html, inline css and js.But it is the first time that I register a new extension on Twig and I am bit confused about where I should add the following lines in my project: $twig = new Twig_Environment($loader); $twig->addExtension(new \nochso\HtmlCompressTwig\Extension()); I was reading the Twig's documentation but it didn't helped me much as they put the same example and just add the following: Twig does not care where you save

Unable to create Twig Global Variable in Symfony 4

筅森魡賤 提交于 2020-01-05 04:56:14
问题 I have already done it using Symfony 3.3 but with Symfony 4 it's not working. App\Twig\NotifExt: public function getGlobals(){ $count = 'Hello World'; return array('count' => $count); } twig_extensions.yaml: twig: globals: 'count': '%count%' base.html.twig: <a class="nav-item nav-link" href="#">{{ count }} </a> I have done something similar in the previous version and it's working well, but with Symfony 4 I'm getting the following error: You have requested a non-existent parameter "count".

How to get days difference in twig

六月ゝ 毕业季﹏ 提交于 2020-01-01 09:03:43
问题 how to get days diffrence from current day. tweetedAt: "2015-02-22 09:56:42". twig {% for key,value in data.about %} {% set tweets_date=(value.tweetedAt|date).date("now").format('%a') %} {% endfor %} I have also tried {% set dd='now'|date('d-m-Y') %} {% set tweets_date=(value.tweetedAt|date).dd.format('%a') %} Finally I tried but its giving error: A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{" {% set

How to get days difference in twig

亡梦爱人 提交于 2020-01-01 09:03:07
问题 how to get days diffrence from current day. tweetedAt: "2015-02-22 09:56:42". twig {% for key,value in data.about %} {% set tweets_date=(value.tweetedAt|date).date("now").format('%a') %} {% endfor %} I have also tried {% set dd='now'|date('d-m-Y') %} {% set tweets_date=(value.tweetedAt|date).dd.format('%a') %} Finally I tried but its giving error: A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{" {% set

Twig - display template names if debug mode is enabled

自古美人都是妖i 提交于 2019-12-19 10:33:35
问题 I'm using Twig lately and I was wondering if it is possible to output the template names which are loaded on the page. The best way I can think of is to display the name above the template itself as a html comment. <!-- start @default/_components/_wrapper/form-wrapper.html.twig --> <form> ... </form> <!-- end @default/_components/_wrapper/form-wrapper.html.twig --> I know that I can get the template name by inserting {{ _self.templateName }} but I don't like to add it to every template or

How to install the Intl extension for Twig

≡放荡痞女 提交于 2019-12-17 15:33:12
问题 The Intl extension is an extension for Twig that adds the localizeddate , localizednumber and localizedcurrency filters. How can I install and set up the extension so that I can use those filters in my Twig templates? 回答1: Install the PHP intl extension First of all, you will need the PHP intl extension, as the Twig extension is built on top of that. The Twig Intl extension will throw an Exception if the PHP intl extension is not enabled. Installation instructions can be found in the official

Symfony - Unable to register extension “AppBundle\Twig\Extension\FileExtension” as it is already registered

泪湿孤枕 提交于 2019-12-14 01:15:44
问题 When I try to implement custom Twig Extension in Symfony2-project, I get following error: Unable to register extension "AppBundle\Twig\Extension\FileExtension" as it is already registered. In my app/config/services.yml, I have following: parameters: app.file.twig.extension.class: AppBundle\Twig\Extension\FileExtension services: app.twig.file_extension: class: '%app.file.twig.extension.class%' tags: - { name: 'twig.extension' } In AppBundle/Twig/Extensions/FileExtension, i have: <?php

passing a parameter from a content type to a module

被刻印的时光 ゝ 提交于 2019-12-13 21:59:01
问题 I assumed this would be easy but I am stumped. I have a custom content type that includes an id field. I render these with a basic page template. I have written a small module that creates a block which is populated with data from an external API. Everything works except I cannot seem to figure out how to pass the value of the id from the content of a given page to my module so it can make the API call. It would be a couple of lines of code in straight php, it can't be that complicated in

ClassNotFoundException: Attempted to load class “TwigExtension” from the global namespace

帅比萌擦擦* 提交于 2019-12-13 04:26:28
问题 I'm trying to create a Twig Extension using the service container, but i'm getting a "ClassNotFoundException". Here the exception: ClassNotFoundException: Attempted to load class "TwigExtension" from the global namespace in \path\to\symfony-simple-blog\src\YagoQuinoy\SimpleBlogBundle\Twig\BlogExtension.php line 11. Did you forget a use statement for this class? Perhaps you need to add a use statement for one of the following: Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension Here