Comments (16)
For who are looking into the same question, in symfony it should be registered as service.
For example for intl
# app/config/services.yml
services:
twig.extension.intl:
class: Twig_Extensions_Extension_Intl
tags:
- { name: twig.extension }
http://stackoverflow.com/a/28410279
from twig-extensions.
In Symfony 4.3 with all dependencies updated , this is now into config/packages/twig_extensions.yaml
, just uncomment the line(s) for each extension you wish to activate :
services:
_defaults:
public: false
autowire: true
autoconfigure: true
# Uncomment any lines below to activate that Twig extension
#Twig\Extensions\ArrayExtension: ~
#Twig\Extensions\DateExtension: ~
#Twig\Extensions\IntlExtension: ~
#Twig\Extensions\TextExtension: ~
from twig-extensions.
The line $twig = new Twig_Environment($loader);
is the one where you instantiate Twig itself. Locate it in your code, and this is the place where registering the extension should be done.
If you use a framework which provides a Twig integration, this integration probably provides a way to register extensions, which is what you would need to look for.
from twig-extensions.
I am working with symfony 2.7
Should i put it in my controller ?
I am completely lost, i just want to put the correct format with intl but i can't use it
from twig-extensions.
this is exactly the case I describe above. Given that Symfony handles the twig instantiation itself, it provides a way to register extensions in the setup it does. And the Symfony documentation explains the way to register twig extensions in a Symfony setup: http://symfony.com/doc/current/cookbook/templating/twig_extension.html shows how to write and register an extension. In the case of the Twig_Extensions_Extension_Intl
, the code is already written, so you only need to to the second step. (And http://symfony.com/doc/current/reference/dic_tags.html#twig-extension concerns it too)
from twig-extensions.
Ok but i need an "use" statement but i don't know what to put in my file?
from twig-extensions.
which use statement are you talking about ?
from twig-extensions.
i put the service in my config.yml but i have an error :
Attempted to load class "Twig_Extensions_Extension_Intl" from the global namespace.
Did you forget a "use" statement?
from twig-extensions.
Well, have you installed the twig-extensions package in your project ? It looks like the extension class cannot be autoloaded.
This message is displayed by Symfony when it cannot find the class after autoloading, pointing at a potential mistake. But in this case, loading it from the global namespace is logical, as the class is in the global namespace.
from twig-extensions.
Yes i installed it.
It seems that Symfony is looking for the twig extension class in the cache, i got this fatal error when trying to clear the cache :
Fatal Error: Class 'Twig_Extensions_Extension_Intl' not found {"type":1,"file":"/home/idci/Workspace/symposium2/app/cache/de_/ap_DevDebugProjectContainer.php","line":3398...
I found the twig extension in the vendor
from twig-extensions.
Well, the cache file is the place where it will try to use the class, which is totally logical.
Are you using the composer autoloader or a custom autoloader ?
from twig-extensions.
The composer one, i am not using any custom autoloader
from twig-extensions.
If it can help my application is dockerized, but i am running the composer commands inside the container so i don't see in which way it could be an issue
from twig-extensions.
Excuse me, but i put the extension in the bad composer.json i am a noob...
Thanks for the help!
from twig-extensions.
Please close this issue then (I cannot do it myself. I'm not collaborator on the repo)
from twig-extensions.
In addition to @KojoEnch comment above, you also need to add twig/extensions
to your composer.json
.
For the benefit of anybody stumbling upon this after a minor symfony twig bundle update:
The latter (>= 2.0) versions of twig finally moved their code into proper namespaces, and separated some of the extensions on a separate composer package, hence the breakage above. Solution above by @diimpp doesn't work anymore since twig bundle has introduced an unintentional bc break by working with both twig 1.x and 2.x (some will argue that there's no bc break in twig-bundle, but as far as I'm concerned bc extends also to configuration, not just class interfaces), where the old config now induces symfony to crash.
from twig-extensions.
Related Issues (20)
- Variables in translation not escaped? HOT 10
- Deprecation Warning for Text.php & Fix HOT 1
- Translator decorator error in prod HOT 2
- Feature: Iterable test functions HOT 1
- Trans tag content with variables in them are broken for new versions of Twig.
- Attempted to load class "Twig_Extensions_Extension_Intl" HOT 1
- localized yes/no function for boolean value HOT 1
- Unexpected result of the localizeddate function HOT 1
- How to add IntlExtension with release 1.5.4 HOT 4
- Cannot combine form vars and filter HOT 5
- Please allow Twig 3 HOT 1
- Conflits with doctrine-bundle HOT 4
- Alternative for Date time_diff ? HOT 2
- Support Twig 3.0 HOT 1
- Support Symfony 5 HOT 3
- Php 7.4 preloading on v1.5.4 fails HOT 2
- [intl-extra] Japanese date format issue
- Mark as abandoned on packagist.org HOT 2
- What's the alternative solution for i18n translation which is supported by twig/twig-extension before and is not supported after upgrading to twig/twig:3 HOT 3
- Use GithubActions instead of Travis
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twig-extensions.