• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Replace Homepage until logged in

Scheduled Pinned Locked Moved General Discussion
welcome pagehomepage
15 Posts 5 Posters 4.6k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mootzvilleM Offline
    mootzvilleM Offline
    mootzville
    wrote on last edited by
    #1

    When a user goes to mysite.com/ I want them to go to a Welcome (aka welcome.tpl) screen initially -- unless they are logged in. If they are logged in then mysite.com/ 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?

    Thanks

    A 1 Reply Last reply
    0
  • A Offline
    A Offline
    a_5mith
    replied to mootzville on last edited by
    #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 -->
    
    1 Reply Last reply
    1
  • mootzvilleM Offline
    mootzvilleM Offline
    mootzville
    wrote on last edited by
    #3

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

    1 Reply Last reply
    0
  • mootzvilleM Offline
    mootzvilleM Offline
    mootzville
    wrote on last edited by
    #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?

    A 1 Reply Last reply
    0
  • A Offline
    A Offline
    a_5mith
    replied to mootzville on last edited by a_5mith
    #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 -->
    home.tpl
    <!-- 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)

    <script>
    if (!app.uid && ajaxify.currentPage !== 'login' && ajaxify.currentPage !== 'register' && ajaxify.currentPage !== 'welcome') {
     ajaxify.go('welcome');
    }
    </script> 
    

    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.

    1 Reply Last reply
    0
  • mootzvilleM Offline
    mootzvilleM Offline
    mootzville
    wrote on last edited by
    #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?

    1 Reply Last reply
    0
  • trevorT Offline
    trevorT Offline
    trevor Plugin & Theme Dev Anime Lovers GNU/Linux
    wrote on last edited by trevor
    #7

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

    A 1 Reply Last reply
    0
  • A Offline
    A Offline
    a_5mith
    replied to trevor on last edited by
    #8

    @trevor Ah right, I was close. 😛

    1 Reply Last reply
    0
  • mootzvilleM Offline
    mootzvilleM Offline
    mootzville
    wrote on last edited by
    #9

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

    A 1 Reply Last reply
    0
  • A Offline
    A Offline
    a_5mith
    replied to mootzville on last edited by a_5mith
    #10

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

    1 Reply Last reply
    0
  • mootzvilleM Offline
    mootzvilleM Offline
    mootzville
    wrote on last edited by
    #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?

    A 1 Reply Last reply
    0
  • A Offline
    A Offline
    a_5mith
    replied to mootzville on last edited by
    #12

    @mootzville Oh right, Psychobunny custom built Templates.js

    1 Reply Last reply
    0
  • mootzvilleM Offline
    mootzvilleM Offline
    mootzville
    wrote on last edited by
    #13

    @a_5mith Cool, thanks.

    1 Reply Last reply
    0
  • C Offline
    C Offline
    cfrancois
    wrote on last edited by
    #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.

    PitaJP 1 Reply Last reply
    0
  • PitaJP Offline
    PitaJP Offline
    PitaJ Global Moderator Plugin & Theme Dev
    replied to cfrancois on last edited by
    #15

    @cfrancois IMPORT does not work in widgets

    1 Reply Last reply
    1

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development