Hello guys, recently i'm working with Drupal 8 to develop my page.
But then i struggle on how to overwrite the page--(type).
I've been doing it with Drupal 7 and it works just easy just by creating a file that named page--(type).tpl.php
BUt then in drupal 8 i follow this (https://www.drupal.org/node/2521876) and it still not working.
Can somebody help me? i've been searching for almost a week, and trying to do what other ppl do, but i cant seems to overwrite it.
Is this feature (somehow) need more configuration?
What currently i had done :
1. on my_theme.theme, i put this code in the most bottom of the file
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function onlinepajak_theme_suggestions_page_alter(array &$suggestions, array $variables) {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$content_type = $node->bundle();
$suggestions[] = 'page__'.$content_type;
}
}
2. i create a file named page--blog_page.html.twig || page--blog-page.html.twig || page--blogpage.html.twig
and my machine name for that content type is blog_page.
It stressed me out , because this is the only way i can differ my content types styling and structure. (as far as i know, if there's another way, i might want to know it :) )
Thank you before. !
Comments
Hello,
Hello,
Please find following link it might be help you
https://www.drupal.org/node/2521876#comment-10684366
Hello @mansigajjar,
Hello @mansigajjar,
Thank you very much for replying on my post.
I don't really know if that's what i want to do..
What i understand from this code ( i am not that good ) is this will limit the change only for specific node?
Because i want to style the page based on content types rather than create file for every node that takes that content types.
Or maybe i understand it wrong?
Thank you btw !
If debugging was enable then
If debugging was enable then all the template names are printed in the source code comments it shows all possible template suggestions for all templates and which one is being used
It doesn't really matter,
It doesn't really matter, both do the same thing for content types. All the code from https://www.drupal.org/node/2521876#comment-10684366 does differently is allow you to override with a node ID based template if you need to. This is a common requirement which is why I posted that code.
Turn on debugging - see this help page: https://www.drupal.org/node/1903374 is pretty crucial when working with Drupal twig templates that you learn how to setup and use debugging, it will help you solve many simple problems.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Debugging
Hi Jeff, Thanks for the reply and help.
So after a week trying to do it and search about debugging, i still had no clue how to do it.
even thou i aldy set it up.. i cant seems to makes the
{{ dump(var) }}to worki have this code on services.yml but it doesn't seems to help me..
And then today upon me searching on the web, i found out something interesting.. i don't know if this is wrong or not, but i hope you could help me.
so my function is
function onlinepajak_theme_suggestions_page_alter(array &$suggestions, array $variables) {}and i REALIZE that 'HOOK' should be the machine name for my theme hook.. but i tried to find out i don't know where to find it (the name of my hook) i hope this could solve my problem. (is it even the problem?)
THank you before.
still not working
hello, can somebody help me..
really not working.. i already turn on the debugging, but the only suggestion the debugging gave me is page--node--*
it's not even close to the content type :(
i really2 desperated on this.. i dont understand why its not called..
do i hook_theme_suggestions_HOOK_alter should become onlinepajak_theme_suggestions_content_type_alter instead?
OR maybe i neeed to correct the naming way of my file? maybe page--type--blog-page?