Override default blocks in a package
Permalink
I'm trying to override default view.php and view.css files of default blocks from within my package, but it will not work.
I can override these in my root/blocks/ folder, but they have no effect from within my root/packages/my_package/blocks/ folder. I can only change the view from within my package if I create a custom template (templates folder) and then manually change the template of the block on my site.
I am also not able to set a template view from within my package if I use this structure:
my_package/blocks/tags/templates/my_template/view.php
The template does display if I use:
my_package/blocks/tags/templates/my_template.php
There seems to be some issue with using files called "view.php" when trying to override within my package.
Is there something I'm missing or any suggestions? I'd really like to be able to override the defaults for my theme without users having to manually select a custom template.
Thanks!
I can override these in my root/blocks/ folder, but they have no effect from within my root/packages/my_package/blocks/ folder. I can only change the view from within my package if I create a custom template (templates folder) and then manually change the template of the block on my site.
I am also not able to set a template view from within my package if I use this structure:
my_package/blocks/tags/templates/my_template/view.php
The template does display if I use:
my_package/blocks/tags/templates/my_template.php
There seems to be some issue with using files called "view.php" when trying to override within my package.
Is there something I'm missing or any suggestions? I'd really like to be able to override the defaults for my theme without users having to manually select a custom template.
Thanks!
I don't think you're understanding my issue exactly.
I'm not trying to override a block within a package, I am trying to override a core block's view.php file from within my package.
So, for the google_map block, I want to add some extra markup around the map by default, so I have added this in my package:
my_package/blocks/google_map/view.php
And then I have modified the view.php file from the original located in the concrete/blocks/googl_map directory... Supposedly my view.php file should override the core view.php file, but it does not.
I'm not trying to override a block within a package, I am trying to override a core block's view.php file from within my package.
So, for the google_map block, I want to add some extra markup around the map by default, so I have added this in my package:
my_package/blocks/google_map/view.php
And then I have modified the view.php file from the original located in the concrete/blocks/googl_map directory... Supposedly my view.php file should override the core view.php file, but it does not.
replying for the sake of it even though it's been over 6 months.
it wasn't possible around the time you asked about it and i don't think anything's changed since then since there's only been one update in between.
i looked at the core code and it was pretty obvious there was no support for it.
it makes sense in one way as you may have 10+ packages and there's no way to know what packages might contain these overrides which essentially would mean that every installed package would have to be checked for a view.php override for every single rendered block including content blocks etc.
on the other hand, it makes little sense from a developers perspective as you ideally want to keep custom developments within packages which makes it a pain in the ass when you want to do something as simple as this.
the only workaround i've used is either put the view.php in the site's blocks folder and break the package isolation (if you're even able to) or use a custom "general" template that you instruct the editor to always pick.
it wasn't possible around the time you asked about it and i don't think anything's changed since then since there's only been one update in between.
i looked at the core code and it was pretty obvious there was no support for it.
it makes sense in one way as you may have 10+ packages and there's no way to know what packages might contain these overrides which essentially would mean that every installed package would have to be checked for a view.php override for every single rendered block including content blocks etc.
on the other hand, it makes little sense from a developers perspective as you ideally want to keep custom developments within packages which makes it a pain in the ass when you want to do something as simple as this.
the only workaround i've used is either put the view.php in the site's blocks folder and break the package isolation (if you're even able to) or use a custom "general" template that you instruct the editor to always pick.
If a package is at risk of being upgraded, I'd just create a custom package and install alongside -- and perform an automated upgrade on the original package and then manually upgrade the customized version.
Otherwise, modifying the original package proper is also another approach which obviously avoids the issues you note.
Others, with more experience in this, may have some better ideas.