Replace Homepage until logged in
-
@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?
-
@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 tologin
Updated script to avoid the redirect loop.
-
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 innext
to the method you can't provide more than 1 route? How is it getting the main route plus the api route? -
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 awelcome.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 inwelcome_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 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
, thenbegin
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 theELSE
, it works fine, it is just theIMPORT
that does not work. -
@cfrancois IMPORT does not work in widgets