4

I want this result:

<a href="path/to/something">This is a link! <span>with a span inside!</span></a>


This renders a link:

$render = array(
  'link' => array(
    '#type' => 'link',
    '#title' => t("This is a link!"),
    '#href' => "path/to/something",
  ),
);


Why does this not render a span inside the link?

$render = array(
  'link' => array(
    '#type' => 'link',
    '#title' => t("This is a link!"),
    '#href' => "path/to/something",
    'span' => array(
      '#type' => 'markup',
      '#markup' => ' <span>with a span inside!</span>',
    ),
  ),
);


Thanks in advance!

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
tolborg
  • 612
  • 4
  • 21

2 Answers2

2

Just adjust your code to be:

$render = array(
  'link' => array(
    '#type' => 'link',
    '#title' => "<span>" . t("This is a link!") . "</span>",
    '#href' => "path/to/something",
     '#options' => array(
        'html' => TRUE,
    )
  ),
);

Hope this works... Muhammad.

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
0

For the #title property just put the span in it like this: '#title' => t("This is a link! with a span inside!")

Jeff Wooden
  • 5,339
  • 2
  • 19
  • 24
  • Sadly the span tags in your answer don't show up. They can be seen by clicking the edit button. – AdamS Feb 04 '18 at 09:44