Display custom HTML in certain pages
-
I installed the plugin and created a new page. What I can't figure out is how to redirect registered users (when logging in or already logged in) to the main categories page (or home page route) while keeping 'guests' on the newly created html page (with no access to any other page). Does that make sense?
-
No you're not wrong on that part, I forgot that the custom homepage doesn't work that way, maby it would be possible for you to edit the source of the plugin to redirect the logged in users?
-
You can check the app.template variable and only show the banner where you want it.
<div id="unregistered" class="hide">Some message</div> <script> if (app.template === "categories") $('#unregistered').removeClass('hide'); </script>
-
@yariplus Thanks for your reply! That's actually a good idea and I think it could work. Although, I've been working on some sort of workaround and I think I found it.
My only problem now is the categories widget isn't styled the same way as the homepage's categories... Here's a photo comparison:
This is how I want it to look:
And this is how it looks when I add the categories widget to the content:
-
@ef What I would suggest is use the normal categories homepage instead of a custom one and redirect users based on app.user.uid, it will be false if the user is a guest.
<div id="unregistered" class="hide">Whatever</div> <script> if (!app.user.uid) { // If Guest... if (app.template === "categories") { // If on categories page show banner $('#unregistered').removeClass('hide'); }else{ // If not on categories page redirect ajaxify.go('categories'); } } </script>
-
@yariplus I'll give it a shot tomorrow, but I agree it's the best future proof way of doing it. I've been working on this all day long now, so I'm a bit tired.
Any recommendations on the categories thing? Just in case I come across the problem in the future.
-
You would need to copy the categories.tpl from theme-persona to widget-essentials, and probably rename the variables. You'd also have to edit widget-essentials source to pull the recent replies if you want that part to work too. I wouldn't recommended doing all that though unless you have a very specific use case for it.
-
@yariplus said:
You can check the app.template variable and only show the banner where you want it.
<div id="unregistered" class="hide">Some message</div> <script> if (app.template === "categories") $('#unregistered').removeClass('hide'); </script>
This worked great! Thanks a million! You're awesome
-
@yariplus Sorry to bother you again... Just in case I want to use this script to display messages on certain pages... How can I do that? What I'm trying to do is display a message in the header in a specific category: (i.e. /category/5/general-discussion).
-
@ef For a specific page, use
window.location.pathname
e.g.
<div id="unregistered" class="hide">Some message</div> <div id="special" class="hide">Some special message</div> <script> if (app.template === "categories") $('#unregistered').removeClass('hide'); if (window.location.pathname === "/category/5/general-discussion") $('#special').removeClass('hide'); </script>
-
Is the display real time? For another user in the same page.