# Hoe de functie van inloggen om inhoud te bekijken te implementeren, om gebruikers beter te werven voor registratie

**URL:** https://meta.discourse.org/t/how-to-implement-the-function-of-logging-in-to-view-content-in-order-to-better-attract-users-to-register/279350
**Category:** Support
**Created:** [18 september 2023 om 06:29 UTC](https://meta.discourse.org/t/how-to-implement-the-function-of-logging-in-to-view-content-in-order-to-better-attract-users-to-register/279350 "2023-09-18T06:29:00Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![go\_ahead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/go_ahead/32/254371_2.png) [@go\_ahead](https://meta.discourse.org/u/go_ahead)
#### Post date: [18 september 2023 om 06:29 UTC](https://meta.discourse.org/t/how-to-implement-the-function-of-logging-in-to-view-content-in-order-to-better-attract-users-to-register/279350/1 "2023-09-18T06:29:00Z")

</div>

As the title suggests, I searched the forum and only found how to change the security of categories, but this only makes all categories invisible, which is not the functionality I need.

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

My use case is: unregistered users can view some post content, and hidden content can only be viewed after logging in. Or registered users need to reply to the post to view it.

This is a means to attract registrations and also to prevent most leechers.

Similar to

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

---

<div class="post-metadata">

### Author: ![go\_ahead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/go_ahead/32/254371_2.png) [@go\_ahead](https://meta.discourse.org/u/go_ahead)
#### Post date: [18 september 2023 om 06:36 UTC](https://meta.discourse.org/t/how-to-implement-the-function-of-logging-in-to-view-content-in-order-to-better-attract-users-to-register/279350/2 "2023-09-18T06:36:24Z")

</div>

## How to achieve the function of logging in to view content, in order to better attract users to register

As mentioned in the question, I searched in the forum and only found the security of changing categories, but this will only make all categories invisible, which is not the function I need.

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

My usage scenario is: unregistered users can view a portion of the post content, while hidden content can only be viewed by logging in. Alternatively, to register as a user, you need to reply to the post in order to view it.

This is a means of attracting registration and also preventing the majority of reaching out parties.

Similar to：

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

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [18 september 2023 om 06:59 UTC](https://meta.discourse.org/t/how-to-implement-the-function-of-logging-in-to-view-content-in-order-to-better-attract-users-to-register/279350/3 "2023-09-18T06:59:06Z")

</div>

> [@go\_ahead](#):
>
> My usage scenario is: unregistered users can view a portion of the post content, while hidden content can only be viewed by logging in.

Is what you are asking for similar to what a lot of news papers do? For example, as an anonymous user, I can view the front page and category pages of the New York Times:

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/0/d/d0de1d0fd541ddc8b47cf46392610aea55c18798.jpeg)

If I then try to visit an article, I’m shown something like this:

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

The reason I am asking in this way is because I think the idea has been mentioned on this forum a few times. I like the idea. It might be useful to show that this is a common way that subscription based publications get users to subscribe. The idea _might_ be useful for some Discourse sites - especially sites that are trying to attract paid subscribers.

---

<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: [18 september 2023 om 07:02 UTC](https://meta.discourse.org/t/how-to-implement-the-function-of-logging-in-to-view-content-in-order-to-better-attract-users-to-register/279350/4 "2023-09-18T07:02:27Z")

</div>

Does this theme component do what you want to achieve?

> [@Guest Gate Theme Component](https://meta.discourse.org/t/guest-gate-theme-component/225107):
>
> Hello wave This theme component is created from [Guest Gate (Sign Up Popup Plugin)](https://meta.discourse.org/t/guest-gate-sign-up-popup-plugin/56625/). It can lock topics for anon visitors with a modal and force them to Sign Up or Login. The component can be use for an alert modal, encouraging visitors to sign up but allowing them to close the modal (for this, leave the dismissable false setting unchecked). Options include changing the number of topics that can be viewed before the modal is displayed. Tip: If you use the …

---

<div class="post-metadata">

### Author: ![go\_ahead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/go_ahead/32/254371_2.png) [@go\_ahead](https://meta.discourse.org/u/go_ahead)
#### Post date: [18 september 2023 om 07:27 UTC](https://meta.discourse.org/t/how-to-implement-the-function-of-logging-in-to-view-content-in-order-to-better-attract-users-to-register/279350/5 "2023-09-18T07:27:26Z")

</div>

> [@simon](#):
>
> I like the idea.

Yes, simon，because my website will have many software download links, but I don’t want unregistered users to see it and click it.thank you for your reply！

I would really like it if it was like spoiler mode.—\> download links When an unregistered user clicks, a registration pop-up window or payment pop-up window will appear, which will be very elegant.

“Unable to view content without replying”–Active users selflessly share their knowledge and they want more responses to their posts. This is also what the forum owners want. I think this feature is beneficial to the development of the forum.

> [@Lilly](#):
>
> Does this theme component do what you want to achieve?

I will try using this plugin.thank you,lilly！

---

<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: [18 september 2023 om 07:32 UTC](https://meta.discourse.org/t/how-to-implement-the-function-of-logging-in-to-view-content-in-order-to-better-attract-users-to-register/279350/6 "2023-09-18T07:32:02Z")

</div>

> [@go\_ahead](#):
>
> I will try using this plugin.thank you,lilly！

You’re welcome, I hope it works for you. Just note that it is a theme component and not a plug-in, so you can install it from the admin UI.

---

<div class="post-metadata">

### Author: ![Don](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/don/32/228726_2.png) [@Don](https://meta.discourse.org/u/Don)
#### Post date: [18 september 2023 om 10:01 UTC](https://meta.discourse.org/t/how-to-implement-the-function-of-logging-in-to-view-content-in-order-to-better-attract-users-to-register/279350/7 "2023-09-18T10:01:21Z")

</div>

I think the [Gated Topics in Category](https://meta.discourse.org/t/gated-topics-in-category/225454) theme component is doing the same. 🙂

---

<div class="post-metadata">

### Author: ![Lhc\_fl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lhc_fl/32/268115_2.png) [@Lhc\_fl](https://meta.discourse.org/u/Lhc_fl)
#### Post date: [18 september 2023 om 11:16 UTC](https://meta.discourse.org/t/how-to-implement-the-function-of-logging-in-to-view-content-in-order-to-better-attract-users-to-register/279350/8 "2023-09-18T11:16:51Z")

</div>

> [@go\_ahead](#):
>
> “Unable to view content without replying”–Active users selflessly share their knowledge and they want more responses to their posts. This is also what the forum owners want. I think this feature is beneficial to the development of the forum.

This is easy to do. There is an attribute in the topic model that shows whether you have replied to it. It is called `posted`. I wrote a component before ( [Composer tip under specific tag topics](https://meta.discourse.org/t/composer-tip-under-specific-tag-topics/255618/1) ) that determines whether you have replied. If you have a programming background, you can take a look at what I wrote. Combined with the `decorateCookedElement` method of the API, it can be implemented to hide content when not replied to.

I am too lazy to write the specific code. I have been very busy recently.

```plaintext
<script type="text/discourse-plugin" version="1.6.0">

const user = api.getCurrentUser();

const I18n = require("I18n");

const pid = "post_hider"

const tl4_css = `
.d-editor-preview [data-theme-hide] {
  background: var(--tertiary);
  color: var(--secondary);
  border-top: 2px solid var(--secondary);
  position: sticky;
  top: 0;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.d-editor-preview [data-theme-hide]::before {
  content: "This post is hidden";
}
`

api.addPostClassesCallback((attrs) => {
if (attrs?.cooked?.includes(`div data-theme-hide="true"`)) {
  return ["hiddened"]; // For adding CSS, how you write the CSS next is up to you
} else {
  return [];
}
});

if (!user) {
    api.decorateCookedElement((el, helper) => {
        function hide_post() {
            setTimeout( () => {
                try {
                    // document.querySelector(`[data-post-id="${helper?.widget?.attrs?.id}"]`)?.parentElement?.remove();
                } catch (err) {
                    console.log(el);
                    console.log(err);
                }
            }, 1000);
        }
        if (el?.querySelector(`[data-theme-hide="true"]`)) {
            el.innerHTML = `<p>Post hidden by community</p>`; // Modify this line
            hide_post();
        }
    }, {
        id: pid,
        afterAdopt: true,
        onlyStream: true,
    });
}

</script>

```

I remembered that I have a piece of code here that I used to hide **the entire post** from non-logged-in users. You can use it for reference.

---

<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: [18 oktober 2023 om 11:17 UTC](https://meta.discourse.org/t/how-to-implement-the-function-of-logging-in-to-view-content-in-order-to-better-attract-users-to-register/279350/9 "2023-10-18T11:17:30Z")

</div>

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