Showing only excerpts (selectively) for not logged in users


(EW 👌) #1

What if we have the ability to show only excerpts for not logged in users in a chosen topics. But this excerpt position and length are defined when needed by the author of the topic.

This could be defined into any topic content (without the need to do any general setup) by placing a special code (just like HTML code special to Discourse).

The code could be any thing like:
<x> shown text </x> hidden text.
or
<x-start> shown text <x-end> hidden text.
or
<excerpt> shown text </excerpt> hidden text.


Example:

<excerpt> Here is a text seen by anyone " whom allowed in the related category security setup default" </excerpt> and here is the rest of the topic’s text which shown only to the logged in users “which is also considering the related cat security”.


So Everyone see only excerpted area with ( … login to continue) added:
Here is a text seen by anyone " whom allowed in the related category security setup default"… (login to continue)

Logged-in users see all topic content:
Here is a text seen by anyone " whom allowed in the related category security setup default" and here is the rest of the topic’s text which shown only to the logged in users “which is also considering the related cat security”.


The main idea is to improve the rate of registered/logged in users and to be able to bring them back more frequently by the summary emails.

The usage of this feature could be selected only on some topics which the author/moderator believe that the user would need to see the rest, so he would register.


(Simon Cossar) #2

The ‘excerpt’ class is whitelisted for the span tag, so you could try wrapping the excerpt in <span class="excerpt"></span> tags and then add a site customization to display only the excerpt for non-logged in users.

This works, but I’m not sure if it will have any unintended side effects:

<script type="text/discourse-plugin" version="0.5">
      
    const anonExcerpt = ($elem) => {
        const currentUser = api.getCurrentUser();
        const excerpt = $elem.find('.excerpt').html();
        
        if(!currentUser) {
            $elem.html(excerpt + ' <strong style="white-space:nowrap;">( ...login to continue)</strong>');
        }
    }
    
    api.decorateCooked(anonExcerpt);
</script>

(EW 👌) #3

Thank you @Simon_Cossar but it’s sound a bit complicated even for me :slight_smile:

I think this request would be easy to do as a standard Discourse feature (with little time, but sure for an expert touch) in case found useful to every body. And I hope it would be so.

I believe it would be useful and used by many. It’s provide the ability for a gentle push to increase registered users.