If I write a snippet of code in the Header (i.e. a banner or advertisement message), is there a way to wrap the code in something that ensures it only gets display to logged in users?
hi,
I’m looking for something similar.
i want to show a static html menu at the top, which should only be visible for registered users.
I would be interested in a solution too.
best regards,
Daniel.
Perhaps like this - wrap it in a div, i.e. logged_in_content
and hide it from users who are not logged in:
html.anon div#logged_in_content {
display: none;
}
as mentioned by @Falco:
I don’t want to hide it.
i want to deliver the html block to registered users only.
This will display it to those who are logged in and hide for those who are not.
yes, i know how css works
but this is no solution.
i dont want that not logged in users can see the html in page-source or it can be indexd by search engines.
its a closed forum and hiding with css is no solution.
i already tried this in the admin backend:
https://meta.discourse.org/t/adding-plugin-outlets-using-a-theme/32727/12
but without success.
the script tag an inner-html is not published.
Can something similar be done for hiding HTML from certain Groups? Or is a simple CSS solution too much to ask for this?
Edit: I misspoke. I didn’t mean individuals, just Groups. @pmusaraj @omarfilip
Search meta for either “currentUser” or “api.getCurrentUser” and you should see several code examples. You can use this to determine whether a user is loggedin, and then act accordingly.
Check if this method is still valid:
I’m not sure, but explore this topic:
this is a good solution, I have tested, but unfortunately not what I am looking for.
I’m looking for a server side solution, not a client side (css/js) solution.
Why do you have to have a server-side solution? Discourse is a full JS app, all of the header components for example have their html generated in JS. You can write the group-specific html in JS, and it will never be displayed to non-group users.
because my html content i want to show is only for logged-in users.
with this js solution every not logged in user can access the .js file over the url which is included always (in the login page too)
http_s://forum.domain.tld/theme-javascripts/83c1451748e441c882ef44430f033c57bb1ab1dd.js
and can see my js-injected html thats only for logged-in users.
i need a secure solution, not css/js pseudo secure solution.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.