# Открытие формы входа через onclick в компоненте темы

**URL:** https://meta.discourse.org/t/opening-the-login-form-with-onclick-in-a-theme-component/275464
**Category:** Development
**Tags:** plugin-api
**Created:** [16.Август.2023 21:01:23 UTC](https://meta.discourse.org/t/opening-the-login-form-with-onclick-in-a-theme-component/275464 "2023-08-16T21:01:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)
#### Post date: [16.Август.2023 21:01:23 UTC](https://meta.discourse.org/t/opening-the-login-form-with-onclick-in-a-theme-component/275464/1 "2023-08-16T21:01:23Z")

</div>

Я долго искал перед публикацией, но не смог найти. Я немного изменяю [этот компонент темы](https://meta.discourse.org/t/new-topic-button-on-all-pages-theme-component/84551) и добавляю кнопку создания новой темы. Я хочу, чтобы неавторизованные пользователи открывали область входа при нажатии на эту кнопку. Файл, который я пытаюсь исправить, — это часть preclick здесь: [https://github.com/KilicSelcuk/discourse-new-image-ask-topic-button-theme-component/blob/main/common/header.html](https://github.com/KilicSelcuk/discourse-new-image-ask-topic-button-theme-component/blob/main/common/header.html)

Я хочу сделать кнопки видимыми вместо того, чтобы скрывать их, и побуждать пользователей войти в систему или зарегистрироваться, чтобы использовать эту функцию.

Спасибо.

---

<div class="post-metadata">

### Author: ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)
#### Post date: [20.Август.2023 18:39:45 UTC](https://meta.discourse.org/t/opening-the-login-form-with-onclick-in-a-theme-component/275464/2 "2023-08-20T18:39:45Z")

</div>

> [@Open the login popup Or trigger event when button is pressed](https://meta.discourse.org/t/open-the-login-popup-or-trigger-event-when-button-is-pressed/136385/4?u=kuaza):
>
> Thanks for sharing your code +1 If you want the login / sign up modals to show up directly, then you need to use the built-in showLogin and showCreateAccont actions. So instead of this helper.h( "button.btn-primary.btn", { type: "button" }, helper.h( "a", { href: "/signup" }, helper.h("span.d-button-label", "Tham Gia") ) ) you should use something like this for the signup modal helper.attach("button", { label: "sign\_up", className: "btn-primary btn-small sign-up-bu…

Я сделал это вот так.

```plaintext
helper.attach("button", {
      label: "log_in",
      className: "css_class_name",
      action: "showLogin",
      icon: "plus"
      })

```

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [22.Август.2023 14:31:05 UTC](https://meta.discourse.org/t/opening-the-login-form-with-onclick-in-a-theme-component/275464/3 "2023-08-22T14:31:05Z")

</div>

Код кастомизации Discourse значительно изменился с 2018–2019 годов. Эти ресурсы могут быть устаревшими.

Вы пробовали посмотреть, как Discourse сейчас добавляет элементы/кнопки и назначает им действия?

---

<div class="post-metadata">

### Author: ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)
#### Post date: [23.Август.2023 17:14:46 UTC](https://meta.discourse.org/t/opening-the-login-form-with-onclick-in-a-theme-component/275464/4 "2023-08-23T17:14:46Z")

</div>

Честно говоря, я не знаю, где найти такие документы. Если есть руководство и вы его знаете, поделитесь им, и я включу вас в число людей, которых я люблю 🙂
