I use sonata admin bundle and my question
How o overwtite this template ?
vendor/sonata-project/admin-bundle/src/Resources/views/CRUD/list_date.html.twig
'date' => '#SonataAdmin/CRUD/list_date.html.twig',
maybe some approach in config ?
sonata_admin:
templates:
date => '#SonataAdmin/CRUD/list_date.html.twig',
but it's not work's.
I tried created templates/bundles/SonataAdmin/CRUD/list_date.html.twig but still sonata render data in vendor/sonata-project/admin-bundle/src/Resources/views/CRUD/list_date.html.twig
How to corect create overwrite template ?
I tried create like in cookbook templates/bundles/SonataAdminBundle/Resources/views/CRUD/list_date.html.twig and clear cache but still data rendered in old template. I using Symfony 4
You can use standard template override from Symfony. Means it should work with file: templates/bundles/SonataAdminBundle/CRUD/list_date.html.twig.
Related
I'm using symfony and in my bundle I need to create some translations, but I rather do it in a different domain than "messages", like FOS User Bundle does (they use the FOSUserBundle domain).
So I created a MyBundle.en.yml file with my translations, but they are not loaded. I've read in the documentation I need to do this:
$translator->addLoader('xlf', new XliffFileLoader());
$translator->addResource('xlf', 'messages.fr.xlf', 'fr_FR');
$translator->addResource('xlf', 'admin.fr.xlf', 'fr_FR', 'admin');
$translator->addResource(
'xlf',
'navigation.fr.xlf',
'fr_FR',
'navigation'
);
http://symfony.com/doc/current/components/translation.html#using-message-domains
But where should I do that?
Update
After some investigation, if I run the debug for the translations it says that all the translation I'm using for my domain in the template are missing.
My translation file is located at
src/Acme/Bundle/MyBundle/resources/translations/MyDomain.yml
I tried to located in app/Resources/translation/MyDomain.yml but same result.
I also tried to delete the cache (rm -rf app/cache) but still not working
Symfony will automatically do this for you if you place your files in the correct location(s). You can find a full description of the conventions assumed by Symfony in the documentation: https://symfony.com/doc/current/translation.html#translation-resource-file-names-and-locations
The Best Practices-guide recommends storing them in app/Resources/translations/. Alternatively you can put them in your bundle's translations folder: src/MyBundle/Resources/translations.
Please be aware that you have to specify your domain when using the translator, e.g. in your twig templates. See:
https://symfony.com/doc/current/components/translation.html#using-message-domains
https://symfony.com/doc/current/translation.html#twig-templates
you have to specify the domain name. for example in twig:
{{ some_things | trans({}, 'my_domaine_name') }}
If you have something like x.en.yaml and you want to use it inside a twing template you can do something like this:
{% trans from 'x' %}word_to_translate{% endtrans %}
I've started learning Twig today and wanted to know how I would redirect to another page in my template.
This is my index.php where I also load my homepage.
<?php
require '../vendor/autoload.php';
$loader = new Twig_Loader_Filesystem('../recourses/views');
$twig = new Twig_Environment($loader);
echo $twig->render('pages/home.twig', array(
'project_title' => getProjectTitle()
));
Now my question is: How could I reach this page with an ?
I can't just use <a href ="pages/home.twig"> since it will show the code instead of the page itself.
I've tried searching but couldn't find my sollution.
Hope anyone can explain this to me.
If I unterstand, you are not using Symfony Standard Edition, but some Symfony components + Twig ?
In that case, Twig is only a a templating engine and Symfony functions are missing.
The path function (ShinDarth answer) is provided by a twig extension defined in the Symfony Standard Edition :
http://symfony.com/doc/current/reference/twig_reference.html#path
All the Symfony Standard Edition function are defined at the same page :
http://symfony.com/doc/current/reference/twig_reference.html
Using Twig like you do, you can only pass the path as variable and render it as {{ path_variable }}
Supposing that you have your route named my_route,
then via twig you simple do:
Link to my_route
Documentation: http://symfony.com/doc/current/book/templating.html#linking-to-pages
Is there a way to replace the standard templates with blade ones? I'm using payum with the payum-laravel-package and klarna-checkout gateway.
I've come to the point where i need to replace the template for AuthorizeAction. I noticed i can create a config option of payum.action.authorize but i have zero understanding of how twig works and absolutely not in combination of laravel.
Is there a way to gain a bit more control over the view? Or the AuthorizeAction itself?
I found that all the actions in the KlarnaCheckoutGatewayFactory is configurable, so i tried making a my own AuthorizeAction that extends from the default, and then include it in the config when adding a new gateway to payumBuilder. But i guess that's not supposed to work because i got the following error:
LogicException in ArrayObject.php line 21:
Traversable interface must be implemented in case custom ArrayAccess instance given. It is because some php limitations.
You have to replace payum.action.render_template with the one which support blade. Also you have to overwrite the path to authorize template, something that blade understands.
<?php
/** #var Payum $payum */
$payum = (new PayumBuilder())
->addDefaultStorages()
->addGateway('aGateway', [
'factory' => 'klarna_checkout'
'payum.action.render_template' => new BladeRenderTemplateAction(/* args*/),
'payum.template.authorize' => 'path/to/blade/template',
])
->getPayum()
;
P.S. We can add this render template action to laravel package and made it a default one.
i am currently working on a symfony project,
what i have:
app/Resources/views/mytemplate/
the folder mytemplate contains all of the important twig-views for my web app.
My question is, is there any possibility that third party members can create their own templates which override my "mytemplate" without creating controllers pointing to them ?
Like:
i have this template:
app/Resources/views/mytemplate/home/index.html.twig
An other person could create a new template in the same views directory like:
app/Resources/views/thirdparty/home/index.html.twig
to override my template.
is there any possibilty like this?
Greetings!
Well, to me, you have two possibilities :
The template that you want to be able to be redefined is the one specified with the method renderView() or similar in your controller : in this case, the possibilities are limitless. It's up to you to define the logic layer determining which template has to be rendered. You could for example force the user redefining the template to name it with a specific additional pattern, and then parse the right template to use thanks to a method inherited in all your controllers.
$content = $this->renderView(
$this->getInheritedTemplate('AcmeHelloBundle:Hello:index.html.twig'),
array('name' => $name)
);
The template that has to be redefined is one inherited in another twig template : In this case, it's almost the same. You could imagine writing your own Twig filter/function in order to retrieve the right template. The code should be very similar to the first case.
Hope this helped.
1- How can I register and call my plugin in bootstrap file?
2- Is it a better way to use boostrap file intead of application.ini file for registering and calling my plugins ?
Note: Iam using custom path ('Mylib/Controller/Plugin') for storing my plugins.
Actually I want to convert following 'application.ini' entries
autoloaderNamespaces[] = "Mylib_"
resources.frontController.plugins.CheckHasAccess = "Mylib_Controller_Plugin_CheckHasAccess"
into bootstrap _initPlugin function.
Can some one guide me in this regards with some sample code.
Thanks in advance
1 - You would need first to load your plugin class (via Zend_Loader or require_once)
then create your plugin yourself:
$plugin = new MyPlugin();
then you can call any public method of your plugin you want and at the end you can register it within front controller:
Zend_Controller_Front::getInstance()->registerPlugin($plugin);
2 - if your plugins need to be somehow configured before they can be used by framework - then you can create and configure them yourself (as described above). If they don't need any special actions - then you can let them to be created by Framework automatically.