php - Drupal:如何在链接内呈现跨度?

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


提前致谢!

最佳答案

只需将您的代码调整为:

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

希望这能奏效......穆罕默德。

关于php - Drupal:如何在链接内呈现跨度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12945266/

相关文章:

php - 比较数字时, "And"和 "Or"关键字在 ASP 中的表现如何?

php - cakephp 3.x 同时在两个表中插入数据

unit-testing - 使用 DrupalUnitTestCase 对 Drupal 进行单元测试在数据库设置上失败

drupal 7在自定义模块中提交表单后查询数据库并显示结果

Drupal 8 - 以编程方式将机器名称添加为类 block

CSS 未正确对齐,与另一个框重叠

php - 在 Elasticsearch 中按查询批量更新?

php - 为什么 Heroku 服务器上的 Laravel JWT auth 出现此错误

php - Drupal 电子邮件变量未出现

php - 在哪里实现 hook_search_info 和 _execute 以强制对搜索结果进行语言过滤?