0

I am using replacement patterns to rewrite the results of my content title field with the manufacturers name in front of the title. I am using the following custom text within the title field to accomplish this:

{{ field_tool_manufacturer }}<br>{{ title }}

I am then outputting this field as a custom link, with the path Node/{{ nid }}

Both the manufacturer and title fields render linked to the node correctly, but the problem is that they should be a single rewritten text link, but it's being output as 2 separate links. One link for the manufacturer, and a separate one for the title. This of course isn't optimal for UX as it communicates 2 separate links especially with css hover styling, etc.

The results are the same when removing the <br> line break. The manufacturer field is excluded from the display, and it is not set to be output as a link in the original field. I have tried multiple style settings with no better luck.

I did this with very little trouble in Drupal 7, so I am wondering if this is a bug that I should create an issue for, or if there is a structural change that is causing the 2 links. I'm new to Drupal 8, so I might be missing something simple. Any help would be appreciated, and let me know if I left out any useful info.

Thanks!

1

When rewriting a field into a custom link you have to make sure that the tokens used for the link text aren't formatted as links, because links can't be nested one into the other.

Edit the field settings for the fields corresponding to {{ field_tool_manufacturer }} and {{ title }} and make sure their Formatter option is set to Plain text, or that the option to "link this field to content" is not checked.

Most field settings will be applied to the token in the Rewrite field option, so you have to control the output yourself.

You can test what the field output is by simply viewing the field without any Rewrite options, and if you see the field output as plain text, and not a link, you can proceed to set up the Rewrite options.

  • That was it. The title field was linked to content as well as being rewritten and output as a custom link. The manufacturer field was a taxonomy reference for anyone else reading this, so it has to be set to label, as plain text is not an option. I did have that correctly set though. Thanks! – TonyTheFerg Sep 20 '19 at 1:50

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.