# 使用 decorateWidget 将文本链接添加到标题

**URL:** <https://meta.discourse.org/t/use-decoratewidget-to-add-text-link-to-header/289542>\
**Category:** Development\
**Created:** [2023 年12 月 22 日 13:36 UTC](https://meta.discourse.org/t/use-decoratewidget-to-add-text-link-to-header/289542 "2023-12-22T13:36:25Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![martyn\_thomas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martyn_thomas/32/344874_2.png) [@martyn\_thomas](https://meta.discourse.org/u/martyn_thomas)\
发布日期： [2023 年12 月 22 日 13:36 UTC](https://meta.discourse.org/t/use-decoratewidget-to-add-text-link-to-header/289542/1 "2023-12-22T13:36:25Z")

</div>

我正在尝试使用主题组件将图标和文本链接添加到我们的标题中。

我设法使用以下代码添加了一个图标：

```plaintext
    const { iconNode } = require("discourse-common/lib/icon-library");
    api.decorateWidget('header-icons:before', helper => {
        return helper.h('li.header-dropdown-toggle', [
            helper.h('a.icon', {
                href:'/docs',
                title: 'Document'
            }, iconNode("book")),
        ]);
    });

```

 ![image](https://global.discourse-cdn.com/meta/original/4X/0/b/f/0bf6e3f412c43dfe70090208ae6f1a470887f46e.png)

但我很难在旁边添加一个也链接到“文档”网址的文本。

我尝试添加以下代码 - 但文本没有链接：

```plaintext
        api.decorateWidget('header-icons:before', helper => {
        return helper.h('li.header-dropdown-toggle', [
            helper.h('h3', {
                href:'/docs',
                title: 'Document'
            }, 'Docs'),
        ]);

```

 ![image](https://global.discourse-cdn.com/meta/original/4X/3/8/f/38f02c6e5a693315f19567bcd2495eae38baf234.png)

我错过了什么？

另外，有没有办法将图标放在标题的左侧（在我们的徽标旁边）？

提前感谢。

---

_[View the full topic](https://meta.discourse.org/t/use-decoratewidget-to-add-text-link-to-header/289542)._
