Hi All
We have a requirement whereby we want to display a different navigation menu depending upon the type of user that is logged into our portal. Looking at the Header web template there is a statement near the beginning of the template
<div id="navbar" class="navbar-collapse collapse">
{% assign primary_nav = weblinks["Default"] %}
Is this where I would put the logic, something like:
{% if someusertype = "xyz" %}
{% assign primary_nav = weblinks["xyz navigation"] %}
{% endif %}
{% if someusertype = "abc" %}
{% assign primary_nav = weblinks["abc navigation"] %}
{% endif %}
Is anything else required?
Thanks
Solved! Go to Solution.
Hi @paulsnolan,
Without digging into the code, that looks about right. If the "user type" doesn't change during a session it should work just fine, otherwise you'll need to consider adding {% substitute %} and {% endsubstitute %} tags to bypass the header cache. Signing in and out should also reset the cache, as far as my previous experience has shown.
Hi @paulsnolan,
Without digging into the code, that looks about right. If the "user type" doesn't change during a session it should work just fine, otherwise you'll need to consider adding {% substitute %} and {% endsubstitute %} tags to bypass the header cache. Signing in and out should also reset the cache, as far as my previous experience has shown.
@paulsnolan another thing to add here is that you can access any attribute from the user (even custom attributes) via liquid, i.e.: {% if user.new_type == 1 %}
if you are using web roles to define the type, you can also filter by that:
{% if user | has_role: "Administrators" %}
Power Apps Portals Super User
Hi Oliver
Thanks for the reply
Hi Justin
Thanks for the confirmation that we have the right approach
Hi Justin
We have got around to doing this development but have hit an issue. I have created two different weblink sets for our required navigation based on a user type.
To ensure they both work as expected I have hardcoded each assign primary_nav = weblinks[... in turn in the header web template with the assignment before the start of the OOB 'if primary_nav' statement
e.g.
{% assign primary_nav = weblinks["xyz navigation"] %}
{% if primary_nav %}
<div class="navbar-right menu-bar {% if primary_nav.editable %}xrm-entity xrm-editable-adx_weblinkset{% endif %}" data-weblinks-maxdepth="2" id="navbarright">
<ul class="nav navbar-nav weblinks" role="menubar">
{% for link in primary_nav.weblinks %}
{% unless forloop.first %}
This works fine
However, if I then place the assign inside an if statement, as in my original question, and this if is immediately before the 'if primary_nav' the navigation menu isn't displayed.
e.g.
{% if someusertype = "xyz" %}
{% assign primary_nav = weblinks["xyz navigation"] %}
{% endif %}
{% if someusertype = "abc" %}
{% assign primary_nav = weblinks["abc navigation"] %}
{% endif %}
{% if primary_nav %}
<div class="navbar-right menu-bar {% if primary_nav.editable %}xrm-entity xrm-editable-adx_weblinkset{% endif %}" data-weblinks-maxdepth="2" id="navbarright">
<ul class="nav navbar-nav weblinks" role="menubar">
{% for link in primary_nav.weblinks %}
{% unless forloop.first %}
Is there a scope issue with the liquid assign within the if statement?
Oh man, wrote a full reply before realizing I wasn't signed in.. forgive any shortness here in rewriting.
I don't think it'll be a scope issue, and would likely be the statements themselves. Definitely recommend having a default style just in case, though
var primary_nav = defaultnav;
if (user['new_typecode'].value == 1)
primary_nav = nav1;
if (user['new_typecode'].value == 2)
primary_nav = nav2;
nav = primary_nav;
I think it's likely the issue is in the if statements. Some progressive things I'd try:
I hope this helps!
Justin
Hi Justin
Got this working, my bad. I had some substitution tags in the if statements plus I'd turned the header caching off. I removed the tags and turned the caching on and it worked.
Regards
Paul
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
User | Count |
---|---|
7 | |
4 | |
2 | |
2 | |
1 |