0

I am rather new to Drupal and am trying to understand how the themes, templates, layouts, and fields work.

When editing the content type in the UI on the website for the book type, and "manage fields", the only field available is "body". When I go to the "form display", I see many more fields. When I go to "manage display", I am back to just the body and links mysteriously appears.

Compounding my confusion is the templates used for the module and how there is navigation export twigs but not all the same fields are used. In the templates directory of the book module, I found the twig files to copy to my theme folder and edit, but there seems to me to be missing information. For example, the book-node-export-html.html.twig only has the following code:

<article>
  <h1>{{ title }}</h1>
  {{ content }}
  {{ children }}
</article>

Which is confusing because when I click the print button to export, I see the hidden fields like author and date information fields. I am guessing the content field is generated somehow which includes the authoring information, instead of splitting them out for theming.

In response to twig debugging comments:

I don't have enough experience with Drupal to understand how to phrase what I am asking. I have been "theming" for lack of a better term using the layout builder on content types.

you need to find the right template to customize

This is only part of the issue; I think before I get there, I need to understand why all the fields shown in the "form display" of the content type are not available in the other tabs or in the twig as show above. When I am debugging, the theme the fields I want to modify are not listed. For example, when I go to export the book and look at the html with twig debugging.

<!-- BEGIN OUTPUT from 'core/modules/node/templates/field--node--uid.html.twig' -->
<span>
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'username' -->
<!-- BEGIN OUTPUT from 'core/themes/olivero/templates/user/username.html.twig' -->
<a title="View user profile." href="/user/4">Name, A …</a>
<!-- END OUTPUT from 'core/themes/olivero/templates/user/username.html.twig' -->
</span>
<!-- END OUTPUT from 'core/modules/node/templates/field--node--uid.html.twig' -->

But you can clearly see that is not in the twig above, and I really just only want to modify it for this one display, and not everywhere on the website.

How do I manage this if the gui for the content type doesn't show these fields? See image below:

enter image description here

5
  • It's not clear what your question is. content is not a field; it is a placeholder that is replaced by another template that contains the body field (and other custom fields that you may add via the UI). Twig templates are stacked-- the html template contains the page template, which contains the entity/book template, which contains the book/body template, and so on. So you need to find the right template to customize whatever you want, which you can do with twig debugging: drush twig:debug on Commented Jun 5 at 3:15
  • Yes, you need to enable Twig debugging and then inspect the markup to see which templates are used: drupal.stackexchange.com/a/316894/15055. Then you copy the templates from the original directory into your custom theme's templates directory and start theming.
    – leymannx
    Commented Jun 5 at 8:50
  • I need to understand why all the fields shown in the "form display" of the content type are not available in the other tabs I would put that the other way around to be honest - why would you expect "Publishing status', "URL alias", "URL redirects", "Moderation State", etc. to be available as HTML content to render on the front end? They're intended to be metadata. They're not listed under "Manage fields" because only fields created with the field UI are listed there (body field the only exception, for new content types, which is automatically added, but is still "owned" by field UI)
    – Clive
    Commented Jun 5 at 15:57
  • @Clive Thank you for that perspective. The reason I think of it the other way around is that they are showing up in the html view when viewing the page, if they were just meta data, I would not expect them to be displayed.
    – J C
    Commented Jun 5 at 16:48
  • Yeah, after a re-read I can understand the confusion. Hopefully the module in the answer will solve the problem
    – Clive
    Commented Jun 5 at 20:11

1 Answer 1

0

The fields are missing from "Manage display" because their visibility is controlled elsewhere, specifically in the settings for each content type.

If you edit a content type, under "Display settings" you'll see the "Display author and date information" option - that's what currently controls the author/meta info being displayed.

It's being addressed in core, in the meantime you can use the Manage Display module to get access to the missing base fields.

2
  • But this is the content type? I don't see "Display Settings" in content types, as shown in the screenshots above. As I first stated in my issue "Manage Display" only shows the body. However, the "manage_display" module did add the author information to the manage display tab, however I was unable to use them in the layout builder. The 'base_field_override_ui' module mentioned in the long discussion thread, provides a button that looks like it will add the internal fields in. I have more testing to do on this though.
    – J C
    Commented Jun 6 at 19:28
  • In your screenshot click the "Edit" tab, that's where "Display settings" is. I don't use layout builder so don't know about that I'm afraid, but this answer explains why the fields are "missing" at least. Maybe there's a module which exposes base fields to layout builder somewhere
    – Clive
    Commented Jun 7 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.