Replace Homepage until logged in



  • 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

    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 -->



  • @trevor Ah right, I was close. 😛



  • @trevor Ok, thanks...yes, your way -- and @a_5mith's way -- is probably better. My solution isn't super complicated...it'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.



  • @mootzville Think loggedIn is from https://community.nodebb.org/api/config, 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.



  • @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?



  • @mootzville Oh right, Psychobunny custom built Templates.js



  • @a_5mith Cool, thanks.



  • 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

    @cfrancois IMPORT does not work in widgets


Log in to reply
 

Suggested Topics

  • 15
  • 11
  • 1
  • 12
  • 12
| |