alanost
(Alan)
July 27, 2022, 8:56pm
1
Hello,
I have researched a lot on the Internet and tried myself but found nothing. I must also say that I am new to Ember.js. The more I am happy if someone can help me.
It’s about the bottom code to display a div under the navbar. This works great. However, I only want it to be displayed when
the user is logged in
only on the home page, so URL “/”
<script type="text/x-handlebars" data-template-name="/connectors/below-site-header/custom-homepage">
<div style="height: 200px; width: 200px;background: red"></div>
</script>
th21
July 27, 2022, 10:16pm
2
import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
import { inject as service } from "@ember/service";
export default Component.extend({
router: service(),
@discourseComputed("currentUser")
shouldShow(currentUser) {
const isStaff = currentUser && currentUser.staff;
const lowTrustLevel = currentUser && currentUser.trust_level < 2;
// show banner only for anons and < TL 2
return !isStaff && (!currentUser || lowTrustLevel);
},
@discourseComputed("router.currentRouteName", "router.currentURL")
discoveryRoute(currentRouteName, currentURL) {
return currentRouteName.indexOf("discovery") > -1;
},
});
You can take a look at how meta banner works, it supports conditional login state and path.
3 Likes
alanost
(Alan)
July 28, 2022, 9:21am
3
Thank you, that helped me a lot
1 Like