Getting current URL in templates.
-
Hey guys, I'm toying around with the lavender theme and I've moved the save changes button on the settings pages to the top, in the same bar as the "Edit, Settings, Profile" links.
The problem with this is that it will appear even on /followers and /following.
Is there a way to check if the current URL is /followers or /following in the template file?
Thanks.
-
@William-Haskell There's probably a better/proper way to do it, but something like location.pathname would return /followers or /following. (I think, I'm not exactly number 1 EU on javascript)
I'd probably wait for an official answer on that though.
-
Thanks for that, so in the template how can I use the IF functions, I'm not too sure on this stuff..
<!-- IF location.pathname IS "/followers" --> ?
or = or something else? -
@William-Haskell I won't lie to you buddy. I haven't got a clue. I'll ping @psychobunny because it's his template engine.
-
Thanks
-
Try
<-- IF followers.length --> <-- IF following.length -->
-
If I use that, it displays only on followers/following page.
!followers.length doesn't seem to work and edit.length doesn't work either so I'm not sure how to do this :s
-
You can also use
ELSE
. So, if I'm not mistaken, something like<!-- IF followers.length --> <!-- ELSE --> Code here <!-- ENDIF followers.length -->
May produce better results.
-
Yep, that works, but there's also another pages using the menu at the top that I've just noticed.
Is there a way to check if the page is just settings or edit?
These seem to be the only ones that need the button.
-
We can possibly add the name of the current template into the api return. So that you can do stuff like
<!-- IF account/edit--> only shows up on edit page <!-- ENDIF account/edit -->
in
partials/account_menu.tpl
for example.account/edit
will be true when you are on the urluser/:username/edit
and false everywhere else.So to solve your problem you would have to do
<!-- IF account/edit--> <!-- IMPORT partials/mySpecialButton.tpl --> <!-- ENDIF account/edit --> <!-- IF account/settings --> <!-- IMPORT partials/mySpecialButton.tpl --> <!-- ENDIF account/settings -->
So you can include a special template if the page is edit or settings.
@psychobunny thoughts?
-
yeah that makes sense to me. tbh maybe we should add the name of the template for all returns as a global var? so that there's no confusion for any custom routed api call -> templates such as the above routes
-
sounds gud