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

时间:2012-10-18 00:03:26

标签: php drupal drupal-7 drupal-theming drupal-render

我想要这个结果:

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


提前谢谢!

2 个答案:

答案 0 :(得分:2)

只需将您的代码调整为:

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

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

答案 1 :(得分:0)

对于#title属性,只需将span放入其中:'#title'=&gt; t(“这是一个链接!里面有一个跨度!”)