Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document changes to theme_preprocess_page() and how theme suggestions are being added in Backdrop vs. D7 #225

Open
klonos opened this issue May 23, 2023 · 1 comment

Comments

@klonos
Copy link
Member

klonos commented May 23, 2023

This came up in Zulip:

Oriol Roger:

...we've noticed that in the theme_preprocess_page function of any theme, the array $variables['theme_hook_suggestions'] is empty by default. In Drupal 7, we used to check which page template is currently used, add new ones if needed, and create that template file. For example, add a template like this: $variables['theme_hook_suggestions'][] = 'page__user__login', and then create the file page--user--login.tpl.php.

Do you know how can we control the theme_hook_suggestions array in Backdrop? We'd like to avoid building a Layout for each page.
...
The problem is that in D7 we have templates in a "page" level. This is what I get with devel:

<!-- FILE NAME SUGGESTIONS:
x page--user--login.tpl.php

* page--user.tpl.php
* page.tpl.php
-->

But in Backdrop there're no templates in "page" level, we can only change the Layout and the Block templates:

<!-- FILE NAME SUGGESTIONS:
x layout--boxton.tpl.php

* layout.tpl.php
-->

I guess this is how it works in BD, so all page templates that were working in D7 have to be ported as layouts.

@yorkshire-pudding:

I think you do get suggestions when you get down to the page content level:

<!-- THEME DEBUG -->
<!-- CALL: theme('node__page__full') -->
<!-- FILE NAME SUGGESTIONS:
   * node--page--full.tpl.php
   * node--page.tpl.php
   * node--2.tpl.php
   x node.tpl.php
-->
<!-- BEGIN OUTPUT from 'core/modules/node/templates/node.tpl.php' -->
...

Oriol Roger:

Yes, I've seen that, but those suggestions are node level, so any page that is not a node (like login, homepage, views...) won't have them.

@klonos:

...looking at older issues in the core queue, such as this one here makes be believe that you will need to replace your HOOK_preprocess_page() functions with HOOK_preprocess_layout() (or move the theme suggestions over to that hook implementation instead). Can you please have a look at the suggested code snippet over in that link and let me know if that works for you?

The discussion is still on-going, however, I thought that I should capture this here, so we can eventually return here and document this for posterity. Perhaps somewhere in https://docs.backdropcms.org/converting-themes(?).

@klonos
Copy link
Member Author

klonos commented May 23, 2023

@herbdool:

What are you trying to accomplish @oriol Roger? Our suggestions will depend on your goals and there will be different ways to accomplish them. Everything is blocks in layouts so you will either have to create more layouts or modify block templates, whether it be the user/login or user/* pages and so on.

Or it could be a new block that takes the context of those paths and then displays something else. There's no one answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant