How to append an HTML tag to a field?

by usernameabc   Last Updated July 12, 2018 01:07 AM

On the basic page content type, we have a paragraph field that is set to Plain Text with Link field and below are the paragraph type's fields.

How to append a <a> to the field so that it is displayed right at the end of the field?

Fields:

  1. Description (type = text (formatted, long))
  2. Link (type = link)

Current

Twig template:

{{ content.field_description }}
{{ content.field_link }}

Sample output:

<p>Dramatically create 24/7 paradigms via ubiquitous information. </p>
<a href="some/path/">Read More</a>

Goal

Twig Template:

{{ content.field_description }}

Desired Output:

<p>Dramatically create 24/7 paradigms via ubiquitous information. <a href="some/path/">Read More</a></p>

What we tried and got stuck. When we tried to print the $pr_description field using ksm(), we could not find a method or array where we could append the link to:

mytheme.theme

function mytheme_preprocess_paragraph__plain_text(&$variables) {
  $pr_plain = $variables['elements']['#paragraph'];
  if(!$pr_plain->get('field_link')->isEmpty()) {
    $pr_link_field = $pr_plain->get('field_link')->first();
    $pr_link_uri = $pr_link_field->uri;
    $pr_link_title = $pr_link_field->title;

    $pr_description = $pr_plain->get('field_description');
    ksm($pr_description); // this did not provide method or array such as `#suffix`
  }
}


Related Questions






How can I print subparagraphs?

Updated May 14, 2018 20:07 PM