By dono1 on
To open, very familiar with Drupal 8 Naming Conventions .
In regards to the blocks section, it covers extending blocks via modules. I understand this very well.
At risk of butchering terminology:
Is it possible to extend D8's custom block types without using a module?
For example:
When we theme a custom content type in D8, we would use: node--custom_content_type.html.twig
To further this: printing an image field from the content type, we would use:
{{ content.field_name }}
{# /* Would we follow the same method content.field_name for printing fields from blocks? */ #}- Are we capable of approaching Custom Block Types in the same manner as Content Types?
- Do we follow the same naming convention such as block--custom_block_type.html.twig?
- If this is possible, is it necessary to add theme hook in mytheme.theme so drupal recognizes the template ? I ask this as we've noticed its not necessary with content types.
Any thoughts are greatly appreciated!
Comments
Hello,
Hello,
I'm trying to implement exactly what you explained without any luck.
Same as you" very familiar with Drupal 8 Naming Conventions".
Unfortunately the article doesn't cover the naming conventions for custom block types as it does for custom content types.
I will really appreciate any advice.
Thanks.
Me Too
Sorry I can't help.
Searching for the same answer on my first D8 build.
Love that Beans have 'been' ported to core in the form of custom block types, but wish the was a way to easily target them for theming.
Even a class of 'this-block-style' printed to the block class array would be a massive help.
Of course the perfect solution would indeed be a recognised template naming convention for custom block types.
I dont know what beans is but
I dont know what beans is but you can add a suggestion for a custom block bundle/type by using hook_theme_suggestions_HOOK_alter() in MYTHEME.theme file and clear the cache:
My custom type/bundle is called "Links" and the block instance is titled "Crazy Links".
If you are in twig debug mode you should see something this in the inspector:
You can see the suggestion
block--bundle--links.html.twigis being used, becaus I have created the file and cleared the cache.I can customise the output, e.g. just print the URL from my link field, and set a class using the bundle name (this will be "bundle-links"), note I have had to use a known field to get the bundle, there may be a better way but this was quick and dirty debugging to get this far and it works.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Thanks Jeff
Thanks Jeff!
That works an absolute treat.
Exactly what i was after.
PS ''bean' was a D7 module which allowed you to create 'beans', which like content types could contain custom fields etc.
https://www.drupal.org/project/bean
The module was ported into D8 core as 'custom block types'
Thanks jeff.
works!!!
Thanks!!
Thank you, this worked perfectly.
For Drupal 8.2
For Drupal 8.2
Are you looking for developer? I am looking for a new team.
Same approach I posted, oh...
Same approach I posted, oh... a year ago: https://www.drupal.org/node/2460893#comment-10766412
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Block Type Templates
I developed a module to do this: https://www.drupal.org/project/block_type_templates
Extra check with
Extra check with BlockContentInterface, nice one, this is what people should use.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Good information
Thanks for the information, It's just what I was looking for
I was looking to do the same
I was looking to do the same thinf. I used _preprocess_block. I found the answer here:
https://drupal.stackexchange.com/questions/252201/access-node-from-a-block