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

Add template suggestions for bundle and view mode #14

Merged
merged 2 commits into from
Dec 9, 2020

Conversation

tanc
Copy link
Contributor

@tanc tanc commented Dec 3, 2020

Adds templates suggestions for the bundle and view mode, will look like this:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'localgov_geo' -->
<!-- FILE NAME SUGGESTIONS:
   * localgov-geo--mybundle--myviewmode.html.twig
   * localgov-geo--mybundle.html.twig
   * localgov-geo--myviewmode.html.twig
   x localgov-geo.html.twig
-->

@tanc
Copy link
Contributor Author

tanc commented Dec 3, 2020

Fixes #13

@finnlewis finnlewis self-requested a review December 3, 2020 16:21
Copy link
Member

@finnlewis finnlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial enough clean change, tests pass.
Looks good to me!

@finnlewis
Copy link
Member

CC @cjstevens78 @Adnan-cds @andybroomfield just FYI really, will probably be useful!

Drupal was reporting the template suggestions perfectly fine in the twig debug output but not actually picking them up. This is because everything has to be underscores in the suggestions, which then get converted to dashes.
@tanc
Copy link
Contributor Author

tanc commented Dec 4, 2020

Just had to add a fix as the suggestions weren't actually working. Everything has to be underscores which then get converted to dashes. So while it looked like suggestions were working in the twig debug output they actually weren't getting picked up if you had a file named like one of the suggestions. A classic Drupal WTF!

For example:
$suggestions[] = 'localgov-geo__' . $sanitized_view_mode;
has to be:
$suggestions[] = 'localgov_geo__' . $sanitized_view_mode;

Copy link
Contributor

@Adnan-cds Adnan-cds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Tanc :)

@tanc tanc merged commit 5606a1e into master Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants