Opening the login form with onclick in a theme component

AI-generated summary

In a development-focused discussion titled “Opening the login form with onclick in a theme component,” kuaza seeks help modifying a theme component to show a login popup for non-logged-in users when clicking a new topic button. They reference an existing theme component and share their current attempt using helper.attach with the showLogin action as shown here. Canapin cautions that older documentation (like a 2018/2019 thread) may be outdated and suggests reviewing how Discourse currently handles button actions. kuaza admits they’re unsure where to find up-to-date documentation and humorously requests guidance, promising gratitude. The discussion centers on modern Discourse theme component practices for triggering login flows via button clicks, with an emphasis on current API usage rather than legacy methods.

I searched a lot before posting but couldn’t find it. I am changing this theme component a little and adding a new topic creation button. And I want non-login users to open the login area when they click the button. The file I’m trying to fix is the preclick part here: https://github.com/KilicSelcuk/discourse-new-image-ask-topic-button-theme-component/blob/main/common/header.html

I want to make the buttons visible instead of hiding them and encourage people to login or sign up to use this feature.

Thanks.

I did it this way.

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

Discourse’s customization code has changed a lot since 2018/2019. These resources might be very outdated.

Did you try having a look at how Discourse currently adds elements/buttons and attaches actions on them?

Frankly, I don’t know where to find such documents. If there is a guide and you know it, if you share it, I will put you among the people I love :slight_smile: