I've taken the time to review most of the documentation and familiarize myself with the forward-facing Backdrop interface. Let me just say that I love it; having been a long-time Drupal 7 user I truly love the direction this CMS is going.

That said,  I'm very confused on the theme/layout relationship.

For example: If I make a page and I only want that one page to have a script, I would make a custom html.tpl.php template page for that situation so I could put my script in the head. When I look through all the theme files and layout files, I can't figure out how the HTML is being generated. Where is the body tag? Where is the head tag? Where is opening and closing html tags? Where are these things to be found?

(You might want to consider a "How It Works" section in the documentation: The layout files do X. The theme files do Y. The final output is Z. How do we combine X and Y together to get Z?)

I can't figure it out from what I've read. Maybe somebody can help me get past this stumbling block. I can't start a new project. I want to make a sub-theme (seems the safest way to get started). What should I make it off of (I did see that documentation). All the stuff that I expect to see in a Drupal 7 template section I don't see. How has that process changed?

I need a shove in the right direction - thanks.

 

 

Most helpful answers

not sure if this is helpful (or redundant), but here's a quick thought that would have helped me when i first came to backdrop from drupal 7.

the page.tpl.php file defines the very high level page structure. if your theme does not have one, you can copy the default from the core system module (templates subdirectory), as mentioned above.  mine looks like this:

 

<!DOCTYPE html>
<html<?php print backdrop_attributes($html_attributes); ?>>
  <head>
    <?php print backdrop_get_html_head(); ?>
    <title><?php print $head_title; ?></title>
    <?php print backdrop_get_css(); ?>
    <?php print backdrop_get_js(); ?>
  </head>
  <body class="<?php print implode(' ', $classes); ?>"<?php print backdrop_attributes($body_attributes); ?>>
    <?php print $page; ?>
    <?php print $page_bottom; ?>
    <?php print backdrop_get_js('footer'); ?>
  </body>
</html>

 

the layout file defines the main page content area, which is rendered and contained in the $page variable in the page.tpl.php file, used in this line from above (right after the <body> open tag):

<?php print $page; ?>

i have found it useful to copy the layout file from the layouts directory into my theme's templates directory. after clearing the caches, the layout file in my theme will override the layout file in the layouts directory.

hope that helps some.

 

 

 

Hi there, 

page.tpl.php is in the same place as Drupal: in system.module, specifically at 

core/modules/system/templates/page.tpl.php.

As far as I understand it, when you request a path, Backdrop calls, among other things, menu_execute_active_handler(), which checks for the default route handler, which is almost always layout_route_handler(), which builds the HTML for the page by again calling theme(<whatever layout template you selected for that path when creating the layout at that path). Then menu_execute_active_handler() does a theme('page'...) with this HTML to deliver your complete page, which of course wraps that HTML with page.tpl.php

More or less.

In Drupal it would have been  menu_execute_active_handler(), then theme('page'...) then finally theme('html' ...). More or less.

So where you would have have page templates, we now have layouts (in reality the layout templates; the whole layout process is just really to match a template to a path).

So where you would have had page template suggestions, we have layout visibility conditions. More or less.

After all this though, to answer your specific issue "If I make a page and I only want that one page to have a script" a template wont do, you'd need to use template_preprocess_page I think.

Maybe havent helped much, but thats how I understand it works.

 

Hi Avariz,

I had the same question a few days ago! There's the API page https://api.backdropcms.org/change-records/new-layout-module-implements-drag-drop-model-building-layouts with a change record regarding your question. Main points:

  • html.tpl.php was removed and replaced by page.tpl.php
  • Page templates no longer have automatic path-based suggestions (e.g. page--node-1.tpl.php) but you can recreate suggestions via hook_preprocess_page().

Comments

Olafski's picture

Hi Avariz,

I had the same question a few days ago! There's the API page https://api.backdropcms.org/change-records/new-layout-module-implements-drag-drop-model-building-layouts with a change record regarding your question. Main points:

  • html.tpl.php was removed and replaced by page.tpl.php
  • Page templates no longer have automatic path-based suggestions (e.g. page--node-1.tpl.php) but you can recreate suggestions via hook_preprocess_page().

That helped but I'm still a bit lost. I cant find page.tpl.php anywhere in my downloaded themes folder. Nor in any layout folder. Where does it reside?

Hi there, 

page.tpl.php is in the same place as Drupal: in system.module, specifically at 

core/modules/system/templates/page.tpl.php.

As far as I understand it, when you request a path, Backdrop calls, among other things, menu_execute_active_handler(), which checks for the default route handler, which is almost always layout_route_handler(), which builds the HTML for the page by again calling theme(<whatever layout template you selected for that path when creating the layout at that path). Then menu_execute_active_handler() does a theme('page'...) with this HTML to deliver your complete page, which of course wraps that HTML with page.tpl.php

More or less.

In Drupal it would have been  menu_execute_active_handler(), then theme('page'...) then finally theme('html' ...). More or less.

So where you would have have page templates, we now have layouts (in reality the layout templates; the whole layout process is just really to match a template to a path).

So where you would have had page template suggestions, we have layout visibility conditions. More or less.

After all this though, to answer your specific issue "If I make a page and I only want that one page to have a script" a template wont do, you'd need to use template_preprocess_page I think.

Maybe havent helped much, but thats how I understand it works.

 

not sure if this is helpful (or redundant), but here's a quick thought that would have helped me when i first came to backdrop from drupal 7.

the page.tpl.php file defines the very high level page structure. if your theme does not have one, you can copy the default from the core system module (templates subdirectory), as mentioned above.  mine looks like this:

 

<!DOCTYPE html>
<html<?php print backdrop_attributes($html_attributes); ?>>
  <head>
    <?php print backdrop_get_html_head(); ?>
    <title><?php print $head_title; ?></title>
    <?php print backdrop_get_css(); ?>
    <?php print backdrop_get_js(); ?>
  </head>
  <body class="<?php print implode(' ', $classes); ?>"<?php print backdrop_attributes($body_attributes); ?>>
    <?php print $page; ?>
    <?php print $page_bottom; ?>
    <?php print backdrop_get_js('footer'); ?>
  </body>
</html>

 

the layout file defines the main page content area, which is rendered and contained in the $page variable in the page.tpl.php file, used in this line from above (right after the <body> open tag):

<?php print $page; ?>

i have found it useful to copy the layout file from the layouts directory into my theme's templates directory. after clearing the caches, the layout file in my theme will override the layout file in the layouts directory.

hope that helps some.

 

 

 

A big thanks to all of you!! That was just the shove I needed.

drop's picture
  • html.tpl.php was removed and replaced by page.tpl.php

I wonder if we should provide `html.tpl.php` as a suggestion for `page.tpl.php`.  The things tried by people coming from Drupal 7 should still work. Perhaps we can even log to watchdog that this template file is deprecated, and point them in the correct direction. Add a function `backdrop_deprecated_template()` or similar?