# Используйте decorateWidget, чтобы добавить текстовую ссылку в заголовок

**URL:** https://meta.discourse.org/t/use-decoratewidget-to-add-text-link-to-header/289542
**Category:** Development
**Created:** [22.Декабрь.2023 13:36:25 UTC](https://meta.discourse.org/t/use-decoratewidget-to-add-text-link-to-header/289542 "2023-12-22T13:36:25Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![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)
#### Post date: [22.Декабрь.2023 13:36:25 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)

Но у меня возникают трудности с добавлением текста рядом с ней, который также вел бы на URL документации.

Я пробовал добавить следующее, но текст не является ссылкой:

```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)

Что я упускаю?

Также есть ли способ разместить иконку в левой части заголовка (рядом с нашим логотипом)?

Заранее спасибо

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [22.Декабрь.2023 18:48:38 UTC](https://meta.discourse.org/t/use-decoratewidget-to-add-text-link-to-header/289542/2 "2023-12-22T18:48:38Z")

</div>

В вашем примере вам нужно вставить свой текст здесь:

```js
helper.h('a.icon', {
    href:'/docs',
    title: 'Документ'
}, ["test", iconNode("book")]),

```

Вам потребуется настроить CSS для ссылки.

Например:

```css
padding-inline-end: 2em;
justify-content: space-between;
color: currentcolor;

```

![chrome_Tk18DUhJQQ](https://global.discourse-cdn.com/meta/original/4X/2/0/a/20a6a4ccee110c20e1519471876de776038262bc.png)

> [@martyn\_thomas](#):
>
> Также есть ли способ разместить иконку слева от заголовка (рядом с нашим логотипом)?

Если вы имеете в виду справа:, вы можете попробовать:

```js
api.decorateWidget('home-logo:after', helper => {
    return helper.h('div.d-header-icons', [
        helper.h('a.icon.btn-flat.doc', {
            href:'/docs',
            title: 'Документ'
        }, [iconNode("book"), "Документ"]),
    ]);
});

```

```css
.d-header-icons .icon.doc {
    width: auto;
    gap: 0.5em;
    margin-inline: 1em;
    
    & .d-icon {
        width: 1em;
    }
}

```

 ![image](https://global.discourse-cdn.com/meta/original/4X/6/5/d/65dc226c59922561820baa57418da1c3c75cb724.png)

Я быстро протестировал это. Возможно, вы столкнетесь с некоторыми особенностями, но вы должны уловить общую идею!

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [22.Декабрь.2023 19:03:08 UTC](https://meta.discourse.org/t/use-decoratewidget-to-add-text-link-to-header/289542/3 "2023-12-22T19:03:08Z")

</div>

> [@Custom Header Links](https://meta.discourse.org/t/custom-header-links/90588):
>
> discourse2Summary Custom Header Links allows you to easily add custom text-based links to the header.eyeglassesPreview [Preview on Discourse Theme Creator](https://discourse.theme-creator.io/theme/Discourse/custom-header-links)hammer_and_wrenchRepository Link [GitHub - discourse/discourse-custom-header-links · GitHub](https://github.com/discourse/discourse-custom-header-links)open_bookNew to Discourse Themes? [Beginner’s guide to using Discourse Themes](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966) Install this theme component Features Desktop Mobile (due to very limited space, adding more than one link on mo…

> [@Custom Header Links (icons)](https://meta.discourse.org/t/custom-header-links-icons/86307):
>
> discourse2Summary Custom Header Links (icons) will allow you to easily add linked icons to the Discourse header.eyeglassesPreview [Preview on Discourse Theme Creator](https://discourse.theme-creator.io/theme/Discourse/custom-header-links-icons)hammer_and_wrenchRepository Link [https://github.com/discourse/discourse-icon-header-links](https://github.com/discourse/discourse-icon-header-links)open_bookNew to Discourse Themes? [Beginner’s guide to using Discourse Themes](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966) Install this theme component Features Screenshots Desktop Mobile Settings This component includes a …

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [22.Декабрь.2023 19:19:04 UTC](https://meta.discourse.org/t/use-decoratewidget-to-add-text-link-to-header/289542/4 "2023-12-22T19:19:04Z")

</div>

Правильно, не знаю, почему я не связал эти компоненты, хотя знал об их существовании. 🤦‍♂️

---

<div class="post-metadata">

### Author: ![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)
#### Post date: [22.Декабрь.2023 19:36:55 UTC](https://meta.discourse.org/t/use-decoratewidget-to-add-text-link-to-header/289542/5 "2023-12-22T19:36:55Z")

</div>

Я копался в этих компонентах — хотел немного и того, и другого, ха-ха

---

<div class="post-metadata">

### Author: ![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)
#### Post date: [22.Декабрь.2023 19:58:02 UTC](https://meta.discourse.org/t/use-decoratewidget-to-add-text-link-to-header/289542/6 "2023-12-22T19:58:02Z")

</div>

Сработало отлично — спасибо.

Теперь предстоит провести вечер, борясь с CSS, чтобы изменить цвет шрифта, ха-ха

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [21.Январь.2024 19:58:29 UTC](https://meta.discourse.org/t/use-decoratewidget-to-add-text-link-to-header/289542/7 "2024-01-21T19:58:29Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
