编程语言
首页 > 编程语言> > php – Drupal:如何在链接中呈现跨度?

php – Drupal:如何在链接中呈现跨度?

作者:互联网

我想要这个结果:

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

这会呈现一个链接:

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

为什么这不会在链接中呈现跨度?

$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>',
    ),
  ),
);

提前致谢!

解决方法:

只需将您的代码调整为:

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

希望这有效……穆罕默德.

标签:php,drupal,drupal-7,drupal-theming,drupal-render
来源: https://codeday.me/bug/20190704/1373617.html