Not able to configure "Welcome" page for guest/unregistered users

General Discussion
  • Nodebb 1.7.0 on GCP (Ubuntu 16.04)
    I am not able to configure "Welcome" page for guest/unregistered users.
    I have created a "welcome" page using "nodebb-plugin-custom-pages" plugin.

    I want to route guests/unregistered users to welcome page and already registered/logged in users to categories page.

    I have referred to this 2014 post in this forum and tried to implement suggestions but it didn't work.

    I have tried including below in "categories.tpl" under header section in Extend->Widgets

    <!-- IF !loggedIn -->
    <!-- IMPORT welcome.tpl -->
    <!-- ELSE -->
    <!-- IMPORT categories.tpl -->
    <!-- ENDIF !loggedIn -->
    

    All users, whether logged in or not, are routed to "categories" page or "welcome" page, whichever is configured as "home page" in General -> Home Page.

    I see some issue with the IMPORT statement as page is not displayed.

    I have also tried including above code in "welcome.tpl" header section as well.

    Any suggestions on how this could be achieved?

    Hope, I was able to convey my problem clearly 🤔 .

  • The <!-- IMPORT partial --> syntax doesn't work in widgets right now, and I can't remember a time when that would have worked. The other thread you referenced is talking about using that within a plugin.

    To do this you'll have to either write a plugin, or use Javascript instead. There are two options if you use client-side scripting instead.

    1. Show the categories page by default, and redirect to the welcome page if the visitor is a guest
    2. Show the welcome page by default, and redirect to the categories page if the visitor is signed in

    For option 1:

    • Select Categories at ACP -> General -> Homepage
    • Put the following script in ACP -> Appearance -> Custom Content -> Custom Javascript
    function welcomeGuests() {
        if (app.user.uid == 0 && ajaxify.currentPage === '') {
            ajaxify.go('/welcome');
        }
    }
    welcomeGuests();
    $(window).on('action:ajaxify.end', welcomeGuests);
    

    For option 2:

    • Select Custom and enter welcome as the Custom Route at ACP -> General -> Homepage
    • Put the following script in ACP -> Appearance -> Custom Content -> Custom Javascript
    function redirectLoggedIn() {
        if (app.user.uid != 0 && ajaxify.currentPage === '') {
            ajaxify.go('/categories');
        }
    }
    redirectLoggedIn();
    $(window).on('action:ajaxify.end', redirectLoggedIn);
    

    In my short experience with this, the first option seemed to work best.

  • @PitaJ Thanks a lot for such detailed post.

    I tried both options. I had to write this JS in ACP->Extend->Widgets->global->Global Header section to execute. Writing it in custom-js didn't work.

    Also, solution worked intermittently. Sometimes I got "ReferenceError: $ is not defined" and other times got "ReferenceError: ajaxify is not defined".

    Thanks again for taking time for replying.

  • Did you make sure to toggle the Enable Custom Javascript setting below the editor at ACP -> Appearance -> Custom Content -> Custom Javascript?

  • Oops! Mobile screen and floating save button...never scrolled down.

    I will try enabling it.

  • It worked ! Thanks a lot 👍


Suggested Topics