I am using PAYUM Bundle for the payment gateway integration, and its basic example is working fine, But now I want integrate the payum bundle in application by changing the payum capture action layout and adding extra field payment detail entity.
PAYUM BUNDLE with AUTHORIZE.NET GATEWAY.
Please can anyone help me out.
Thanks all in advance.
The payum templates is not kept in the bundle but in the payum lib itself. Standard templates inheritance does not work here.
There is no simple way to do so in version 0.9 (which is shipped with Sylius right now). You have to overwrite the whole CaptureAction class. In 0.10 it is possible to change templates by overwriting container parameters like for layout, or stripe js page.
In the sandbox you can find an example of layout modification
You have to override views of PayumBundle.
How to do that?
You have to reproduce the folder structure of the bundle you want to override inside your /src/Path/To/Your/Bundle/Resources/views and place inside it the twig file you want to override.
Example
Let's say your bundle name is FooBundle and you want to override PayumBundle payment.twig.html (I'm just making an example, don't know if there's a file named that way). Let's say, also, that this twig is inside /vendor/Path/To/PayumBundle/Resources/views/Payment/payment.twig.html.
What you have to do is create inside /src/Path/To/Your/Bundle/Resources/views/Payment/payment.twig.html
Symfony2 will look, at first, into your bundle for overrided views: if any will took yours and ignore bundles one. Otherwise It will took bundle's one.
Related
I'm a bit confused as I've seen a few varying methods posted online.
I have a bundle created with easyextends in src/Application/Sonata/SonataMediaBundle, which extends the SonataMediaBundle in the vendors.
The default template displays
This is the gallery index template. Feel free to override it.
This file can be found in SonataMediaBundle:Gallery:index.html.twig.
so I've added src/Application/Sonata/SonataMediaBundle/Resources/views/Gallery/index.html.twig in my bundle
and this works and overrides, so why all these various other ways like How to override Sonata Media Bundle templates?
You are using the correct way. To quote from symfonys How to Override Templates from Third-Party Bundles
To override the bundle template, just copy index.html.twig template from the bundle to app/Resources/AcmeBlogBundle/views/Blog/index.html.twig (the app/Resources/AcmeBlogBundle directory won't exist, so you'll need to create it). You're now free to customize the template.
And for more detailed/ complex overriding behaviour have a look at How to Use Bundle Inheritance to Override Parts of a Bundle
I wouldn't worry to much about other solutions unless you are not able to get the results you require using this method but I cant think of one.
I have a problem with a render function in my controller.
I have:
a bundle, named CoreBundle
a controller named DefaultController
in which I have an action named loginAction
in which I am trying to render a template twig with this line
return $this->render('FooCoreBundle::Default:layout.html.twig', array());
I am always having the same not found error for the template. I have tried with an other template twig it is the same problem. In my views folder I have a Accueil folder in which i have put the login.html.twig template I want to render.
I tried to replace it directly in views folder but no changes. Sorry for my english hope you can help. Thank You.
A worth-while reading piece of info from the documentation:
Symfony uses a bundle:directory:filename string syntax for
templates that live inside a bundle. This allows for several types of
templates, each which lives in a specific location.
Supposing:
FooCoreBundle is your bundle -> src/Foo/CoreBundle
Default is the template directory -> src/Foo/CoreBundle/Resources/views/Default
layout.html.twig is your file -> src/Foo/CoreBundle/Resources/views/Default/layout.html.twig
Then the route you should use would be 'FooCoreBundle:Default:layout.html.twig' without the :: you're using in 'FooCoreBundle::Default:layout.html.twig'
The :: refers to a base template specific to the bundle. If you used FooCoreBundle::layout.html.twig then your template should live at Resources/views/layout.html.twig inside FooCoreBundle.
Hope this clarifies things.
You should use
return $this->render('NeobeCoreBundle:Default:Accueil:layout.html.twig', array());
No double colon, add the Accueil subfolder
It is not really an answer, but it could be handy for those who arrives here with symfony 4.
In documentation authors says do not organize your business logic into bundles.
In modern Symfony applications, it's no longer recommended to organize your business logic using bundles.
Of course you can, just not recommended. See here.
I recently configured my website project to use Symfony CMF with Sonata Admin.
I'm now populating my website with random editable simple blocks, but can't figure out the way to override their rendering template.
There are two stacks of templates, once for use with the frontend editing CreateBundle and once without. The one for CreateBundle have a _createphp.html.twig at the end. Are you sure you overwrite the correct template? See https://github.com/symfony-cmf/BlockBundle/tree/master/Resources/views/Block
When I debug such things, i try to edit the template in the vendor folder (make a syntax error, write "HELLO" or whatever) just to see if i am even trying to overwrite the correct template.
In the title of this question you mix sonata and cmf. The cmf block bundle builds on sonata block bundle, but provides a couple of block types. Are you sure you have the paths right?
I am new to symfony2 so please forgive me if this is a stupid question.
Symfony2 is organised in bundles - so everything is a bindle right?
Based on this I have created the following bundles in order to have a simple login mechanism:
App
The main bundle will contain all global functionality
User
Will be used to represent users
So the bundles work correctly and all is fine.
Now I cant figure out the best way to add a layout/theme structure to the site.
I obviously need some global assets such as header, nav and foooter. But additionally, there needs to be some global css style sheets, jquery etc.
The most obvious place bundle is App - but how do i make all other bundles inherit the theme from this bundle. For example, the user bundle template needs to extend the App bundle etc.
The idea for bundles is that they are modular and self contained, therefore how can this be achieved
I personally use like this:
There is MainBundle (in your case, it is App) which does global services, twig extensions and layout. Global assets are included in this file.
Main layout of all the other bundles extends the layout of MainBundle. Templates inside each bundle extend to the main layout of it which extend the layout of MainBundle. For example,
- MainBundle
- views
- layout.html.twig
- UserBundle
- views
- layout.html.twig (extends to MainBundle/layout)
- show.html.twig (extends to UserBundle/layout)
- friends.html.twig (extends to UserBundle/layout)
Everything is explained in the official docs: http://symfony.com/doc/current/templating.html
The basic global view (templates) resources are placed in the following dir:
app/Resources/views/index.html.twig
If you have a specific purpose, or bundles, templates, place them in the subdirs, e.g.:
app/Resources/views/blog/index.html.twig
And if you want to keep everything in the bundle (must for reusable code), use this convention:
[VendorName/]YourBundle/Resources/views/Blog/index.html.twig
(Of course, any name, except the ".html.twig" extension for Twig, may be changed to your liking)
The strategy I prefer is to organize my application in a single bundle. If you have no intention of re-using distinct standalone features across multiple applications then this is the most appropriate way. Having a "UserBundle" in your own application namespace probably doesn't make sense. You're adding a lot of extra structure that's serving you no advantage. Consider this instead:
- MainBundle
- Controller
- UserController
- OtherController
- Resources
- views
- layout.html.twig
- User
- show.html.twig
- update.html.twig
- friends.html.twig
- Other
- some_other_view.html.twig
In this case the templates under the controller directories would extend MainBundle::layout.html.twig.
I want to make an application based on a main bundle leaving the possibility for other developers to make their own bundles to implement other features.
Symfony 2.0 seems a good choice for that however I cannot figure out how to let the bundles to work together while preserving the decoupling.
In the MainBundle I will create a Controller which generates a Users-List like the one below:
user1 edit remove
user2 edit remove
....
How to let third-parties bundles to add their custom buttons to this list?
For example an AvatarBundle may want to add a button to upload of the Image, a SendEmailBundle my want to add a button to send an email to the user and so on.
How to preserve the bundle independency? How can I do that?
Thanks a lot,
Massimo
As far as I know, there are only two ways of changing/adding functionality in provided bundles.
Change the code
Overriding the template/controller
In this case, the second seems far preferable.
The ways to override a template are:
Define a new template in app/Resources
Create a child bundle and override the template
If you also want the override controllers, the second way is the only way to go.
It's also my personal preference, since it's cleaner then putting specific stuff in the general app-folder, in my opinion.
Anyway, it is far better explained in the documentation of the FOSUserBundle:
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_templates.md
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_controllers.md
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_forms.md
And ofcourse, this cookbook article:
http://symfony.com/doc/current/cookbook/bundles/inheritance.html
Hope this helps,
Dieter
If you know which parts of your bundle will be extended, you can use services (in the same way the tiwg bundle is using them for adding new templating filters/tags/helpers).
Your bundle will then 'scan' the services defined in the DIC (which have a defined tag) and then call them to get informations (button definitions in your case).