Replace Homepage until logged in

General Discussion
  • #1

    When a user goes to I want them to go to a Welcome (aka welcome.tpl) screen initially -- unless they are logged in. If they are logged in then would be the nodebb home page (aka home.tpl).

    What's the easiest way to go about this? Modify the '/' route call with an if condition? Or, use the app.load hook? Or maybe a redirect would be easiest?


  • #2

    @mootzville You could use this in your template I believe, you may have to wrap your usual homepage in the same thing, but without the ! though. Their may be a better way however.

    <!-- IF !loggedIn -->
    <!-- ENDIF !loggedIn -->
  • #3

    @a_5mith Awesome, I'll try that. Thanks!

  • #4

    @a_5mith Actually, that's not working for me...I have something like this:

    <!-- IF !loggedIn -->
    <p>You ain't logged in fool!</p>
    <!-- ENDIF !loggedIn -->
    <!-- IF loggedIn -->
    <!-- home.tpl goes here -->
    <!-- ENDIF loggedIn -->

    Any thoughts?

  • #5

    @mootzville Depends what template that's in. If that's in home.tpl then you could add ELSEIF to it. So you'd do.

    <!-- IF loggedIn -->
    <!-- ELSEIF loggedIn -->
    You aint' logged in fool
    <!-- ENDIF loggedIn -->

    But again, their may be a better way of doing it, I know you can do it in a script that redirects you to another page. So if you have the page created, you could do it like this: (This goes in a global header widget)

    if (!app.uid && ajaxify.currentPage !== 'login' && ajaxify.currentPage !== 'register' && ajaxify.currentPage !== 'welcome') {

    welcome being the location of relative_url/welcome, but that page will need to be routed. By default that script should usually go to login

    Updated script to avoid the redirect loop.

  • #6

    Just to follow up...I ended up just replacing this:

    res.render('home', data);

    with this:

    req.user ? res.render('home', data) : res.render('welcome');

    in the src/controllers/index.js file.

    This may or may not have side effects...not sure yet...

    I tried to come up with other ways, but this seems the most straight forward. If there is an approach that this can be achieved via hooks I'd love to know...

    Also, from src/routes/index.js can someone explain this:

    function setupPageRoute(router, name, middleware, middlewares, controller) {
    	middlewares = middlewares.concat([middleware.incrementPageViews, middleware.updateLastOnlineTime]);
    	router.get(name, middleware.buildHeader, middlewares, controller);
    	router.get('/api' + name, middlewares, controller);

    For the router.get() methods, are they like Express' app.get? And if so, I thought unless you pass in next to the method you can't provide more than 1 route? How is it getting the main route plus the api route?

  • Plugin & Theme Dev Anime Lovers GNU/Linux

    Ouch, this looks way too complex and you took it a whole other level.

    I do this on my site, and its faily simple.

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

    This should be in the home.tpl template. You have to create a welcome.tpl and another template (whatever you want to name it is up to you, for example purposes I named the template for when you're logged in welcome_loggedin.tpl) for when you're actually logged in.

    @a_5mith The following template variable does not work for this particular logic: <!-- ELSEIF loggedIn -->

  • #8

    @trevor Ah right, I was close. 😛

  • #9

    @trevor Ok, thanks...yes, your way -- and @a_5mith's way -- is probably better. My solution isn't super's actually achieving the same thing more or less and with a single line of code (plus, the template).

    However, I do much prefer handling it within the theme rather than in core nodebb. Makes it easier to maintain over time.

    My reference to the setupPageRoute function was more out of curiosity.

    And, one last question...these conditionals that are used in the templates; where are they defined? Meaning, where do they come from? I hadn't seen them in html before using nodebb.

  • #10

    @mootzville Think loggedIn is from, but I think any true/false can be used as if/else, then begin would do other bits and pieces. Like cats, topics or posts.

  • #11

    @a_5mith I see, but also where does this:

    <!-- IF !loggedIn --> come from? Not the loggedIn part, but the if condition itself? What is handling the logic?

  • #12

    @mootzville Oh right, Psychobunny custom built Templates.js

  • #13

    @a_5mith Cool, thanks.

  • #14

    This topic is quite old but it is exactly my issue.
    I wanted to define a custom page for not logged people and show category otherwise.

    I used the odebb-plugin-custom-pages plugin. I created a new page,

    add in the html widget of the page the next code :

    <!-- IF !loggedIn -->
    code if not loggedin, work fine
    <!-- ELSE -->
       <!-- IMPORT categories.tpl -->
    <!-- ENDIF !loggedIn -->

    However, the IMPORT doesn't work.
    Every thing is at the same directory. I used <!-- IMPORT ../categories.tpl --> but it didn't work. I restart everything I could restart. Nothing. If I put code and text after the ELSE, it works fine, it is just the IMPORT that does not work.

  • Global Moderator Plugin & Theme Dev

    @cfrancois IMPORT does not work in widgets

Suggested Topics

  • 0 Votes
    9 Posts

  • 0 Votes
    23 Posts

  • 2 Votes
    1 Posts

  • 0 Votes
    2 Posts

  • 0 Votes
    1 Posts

| | | |