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 field--node--body--full template? #60

Open
alisonjo315 opened this issue Nov 16, 2022 · 2 comments
Open

add field--node--body--full template? #60

alisonjo315 opened this issue Nov 16, 2022 · 2 comments
Labels
task A task! A task!

Comments

@alisonjo315
Copy link
Collaborator

alisonjo315 commented Nov 16, 2022

I've seen we end up with a templates for the node body field, for the full view mode -- i.e. field--node--body--full.html.twig (sometimes also field--node--body--default.html.twig).
⚠️ Also needs mytheme_theme_suggestions_field_alter() added to cwd_base.theme to support view mode field templates, like what's in the Bright Beams child theme (cwd_cbb). (See comment in thread below for details.)

For --full, the body gets a div.field-body.double-margin wrapper. For --default, the body gets a div.summary wrapper -- but I think --default isn't used much, because usually there's a specific teaser field, usually the body field isn't shown except on the full view mode.

Is this treatment pretty standard, or just a sometimes thing?

NOTE: If we do this, we'll just need to update a couple templates in cwd_project, that currently put the wrapper markup in the node templates. (Benefit of these field templates is they get used across content types, so you don't have to have duplicate implementation.)

@alisonjo315 alisonjo315 added the task A task! A task! label Nov 16, 2022
@alisonjo315
Copy link
Collaborator Author

alisonjo315 commented Nov 16, 2022

Okay so, here's what I'm suggesting we do -- if a design person tells me this is a standard enough treatment to be worth putting in cwd_base:

  1. Add the template suggestions stuff to cwd_base.theme (copied from cwd_cbb.theme):
/**
 * Implements hook_theme_suggestions_field_alter().
 */
function cwd_base_theme_suggestions_field_alter(&$suggestions, array $variables) {
  $field = $variables['element'];
  $sanitized_view_mode = strtr($field['#view_mode'], '.', '_');
  // Add view mode theme suggestions.
  $suggestions[] = 'field__' . $field['#entity_type'] . '__' . $field['#field_name'] . '__' . $field['#bundle'] . '__' . $sanitized_view_mode;
  $suggestions[] = 'field__' . $field['#entity_type'] . '__' . $field['#field_name'] . '__' . $sanitized_view_mode;
}
  1. Add field--node--body--full.html.twig to cwd_base, with the following content:
{#
/**
 * @file
 * Theme override for node body field, full view mode (any ctype).
 * ~ add div.field-body.double-margin
 *
 * @see field.html.twig
 *
 * @ingroup themeable
 */
#}
<div class="field-body double-margin">
  {% include "@cwd_base/includes/_field--un-wrapped.html.twig" %}
</div>
  1. Create a companion issue on cwd_base, to update the node--news--full.html.twig template (and the same template for people + spotlights) as follows:
--- a/templates/news/node--news--full.html.twig
+++ b/templates/news/node--news--full.html.twig
@@ -20,9 +20,7 @@
   </div>
   {% endif %}
 
-  <div class="field-body double-margin">
-    {{ content.body }}
-  </div>
+  {{ node.body|view('full') }}
 
   {% if node.field_tags.value -%}
     <hr>

@alisonjo315
Copy link
Collaborator Author

@ama39 Could you please take a look at this when you have time? -- not urgent!

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

No branches or pull requests

1 participant