0

It seems that the naming convention for field types is undocumented. Looking at the classy theme shows a seemingly arbitrary convention. For example, the Text (formatted, long, with summary) type as displayed in the UI is apparently named field--text-with-summary.html.twig as a template file.

What are the naming conventions for field types and how could I have determined them myself?

0

1 Answer 1

5

The naming convention for field templates is documented here, Twig Template naming conventions

  • field--node--[field-name]--[content-type].html.twig
  • field--node--[field-name].html.twig
  • field--node--[content-type].html.twig
  • field--[field-name].html.twig
  • field--[field-type].html.twig field.html.twig

But field--text-with-summary.html.twig is one of those that is harder/trickier to figure out from just looking at the Field Type.

enter image description here


To make Drupal life easy for this, you can enable Twig Debug. See Locating Template Files with Debugging

Now when you inspect element with browser, you can see which template file is being used (the one with the "x") and what other available template file names (the ones with "*") you could use.

enter image description here

2
  • I've seen the documentation you linked to, and to clarify, it does not document the naming convention for field types, only the naming convention for templates. By the fact that one has to enable debugging mode and dig through logs to get to the type names, it seems that the type names are undocumented. Commented Jun 1, 2020 at 17:18
  • @glenviewjeff the naming convention for field type is [field-type], but like I said the text-with-summary is a tricky/gotcha one.
    – No Sssweat
    Commented Jun 1, 2020 at 22:02

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.