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

mansigajjar’s picture

Hello,

Please find following link it might be help you

https://www.drupal.org/node/2521876#comment-10684366

rgalaxy’s picture

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 !

mansigajjar’s picture

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

Jeff Burnz’s picture

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.

rgalaxy’s picture

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 work

twig.config:
    # Twig debugging:
    #
    # When debugging is enabled:
    # - The markup of each Twig template is surrounded by HTML comments that
    #   contain theming information, such as template file name suggestions.
    # - Note that this debugging markup will cause automated tests that directly
    #   check rendered HTML to fail. When running automated tests, 'debug'
    #   should be set to FALSE.
    # - The dump() function can be used in Twig templates to output information
    #   about template variables.
    # - Twig templates are automatically recompiled whenever the source code
    #   changes (see auto_reload below).
    #
    # For more information about debugging Twig templates, see
    # https://www.drupal.org/node/1906392.
    #
    # Not recommended in production environments
    # @default false
    debug: true
    # Twig auto-reload:
    #
    # Automatically recompile Twig templates whenever the source code changes.
    # If you don't provide a value for auto_reload, it will be determined
    # based on the value of debug.
    #
    # Not recommended in production environments
    # @default null
    auto_reload: null
    # Twig cache:
    #
    # By default, Twig templates will be compiled and stored in the filesystem
    # to increase performance. Disabling the Twig cache will recompile the
    # templates from source each time they are used. In most cases the
    # auto_reload setting above should be enabled rather than disabling the
    # Twig cache.
    #
    # Not recommended in production environments
    # @default true
    cache: true

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

rgalaxy’s picture

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?