Override template of a Symfony BlockBundle SimpleBlock - symfony

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?

Related

Correct way to override default template in Sonata

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.

How do I load this form theme from my App Bundle? (symfony)

I have an app with the following directory structure in Symfony 2.6
src/
App/
MainBundle/
Forms/
template.html.twig
And I'm trying to use this as a form theme along with the bootstrap3 theme. According to the documentation I can apply multiple themes. So I've updated config.yml to look like this:
# Twig Configuration
twig:
form:
resources:
- 'bootstrap_3_layout.html.twig'
- 'AppMainBundle:Forms:template.html.twig'
However, when I add the second resource I only get a blank page. It must be something to do with the way I'm referencing the template -- I can reference another one of the built-in ones and it works correctly.
Thanks.
Templates need to be saved under the
src/{bundle name}/Resources/views/{subdir}/{twig filename}
e.g.
AppMainBundle:Forms:template.html.twig:
src/App/MainBundle/Resources/views/Forms/template.html.twig

Payum Bundle : How to change the view of capture action in symfony2

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.

symfony 2.0 bundles interworking

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).

In Drupal, how do I override a template in a core module without modifying the actual core?

I want to edit the search results of a search using the search module. The template in question is search-result.tpl.php. I see that it's in html/modules/search, but I'd like to keep the modification out of the core and keep it in my sites folder. Is there a way to change the place that drupal looks for that specific template? If not, how can I accomplish my goal?
Copy the search-result.tpl.php into your theme's directory, modify it as needed, and clear the theme cache.
You may also want to check out the About overriding themable output handbook page for additional details.

Resources