This feels like it should be simple to do, but I can't work it out.

If I have a text field, how do I rewrite the output of the field on the "Manage display" tab of the content type? For example, I might want to add units, or convert a product ID into a link to an external website.

I know how to do this stuff in Views, but it would seem to make sense to be able to do it via the "Manage Display" tab for a content type. Am I missing something?


You can achieve this by creating field.html.twig.

Default theme implementation for a field.

You will get more information:

Override field template (twig)

field.html.twig and field--node--title.html.twig

  • This option was much easier than I thought it would be.
    – James
    Sep 19 '16 at 13:51

You have a couple of choice based on your needs:

  1. Overriding the template file (twig) of the specific field
  2. Using form_hook_alter
  3. For complex and clean solution I suggest you to use a custom widget for your field type.
  • There are also some simple string formatter contrib modules
    – Jonathan
    Sep 20 '16 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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