solved Conditional Sitebuilder Menu Item

TiG
TiG
@tig
6 years ago
184 posts
Is it possible to conditionally hide (or alternatively, conditionally show or dynamically create) a main menu item created using Sitebuilder?

The need is to show a new main menu item (in this case, 'Publish') only for users authorized to use publishing functionality provided by the sub-menu items under Publish. The Publish main menu item would appear only for those who are authorized.



--
TiG

updated by @tig: 07/17/18 04:13:01PM
nate
@nate
6 years ago
917 posts
You want to use the quota settings.
1.jpg
1.jpg  •  72KB

TiG
TiG
@tig
6 years ago
184 posts
Nate

Your answer is perfect if the condition is reflected in a quota. (I should have explicitly excluded that, sorry, my bad.) What I am looking for is the means to disable (or enable or even dynamically create) a main menu item (and sub-items) based on an arbitrarily complex condition expressed in code.

Thanks


--
TiG

updated by @tig: 04/14/18 01:06:23PM
nate
@nate
6 years ago
917 posts
That's not possible with the Menu Editor.
TiG
TiG
@tig
6 years ago
184 posts
Nate

I agree. Been looking for something outside of SB to accomplish this. Ideally an event that would enable a listener to prevent the showing of a menu item.

Thanks


--
TiG
nate
@nate
6 years ago
917 posts
That's a very complicated way. Good ole HTML and smarty code would also work. It's being done for half the menu already.
TiG
TiG
@tig
6 years ago
184 posts
Nate

Okay, then based on your advice I probably should just bypass Sitebuilder menu altogether and bring the full menu into code. That will provide full (developer) flexibility for whatever might arise in the future.

Thanks,
TiG


--
TiG
nate
@nate
6 years ago
917 posts
You can use both if you like. I do.
michael
@michael
6 years ago
7,715 posts
OR you could use a smarty function in combination with the existing menu.

Currently the Site Builder menu is created with the /modules/jrSiteBuilder/templates/menu.tpl file.

You can over-ride that with normal system by copying it to the skin your using and calling it jrSiteBuilder_menu.tpl.

Docs: "Altering a modules template"
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/1051/altering-a-modules-template


The current menu.tpl file looks like this:
{foreach $_list as $_l0}
<li {if $_post.module_url == $_l0.menu_url}class="active"{/if}>
    <a href="{if $_l0.menu_url|substr:0:4 === 'http'}{$_l0.menu_url}{elseif $_l0.menu_url|substr:0:1 === '#'}{$_l0.menu_url}{else}{$jamroom_url}/{$_l0.menu_url}{/if}" onclick="{$_l0.menu_onclick}" class="menu_0_link" data-topic="{$_l0.menu_url}">{$_l0.menu_title}</a>
    {if is_array($_l0._children)}
    <ul>
        {foreach $_l0._children as $_l1}
        <li>
            <a href="{if $_l1.menu_url|substr:0:4 === 'http'}{$_l1.menu_url}{elseif $_l1.menu_url|substr:0:1 === '#'}{$_l1.menu_url}{else}{$jamroom_url}/{$_l1.menu_url}{/if}" onclick="{$_l1.menu_onclick}" >{$_l1.menu_title}</a>
            {if is_array($_l1._children)}
            <ul>
            {foreach $_l1._children as $_l2}
                <li><a href="{if $_l2.menu_url|substr:0:4 === 'http'}{$_l2.menu_url}{elseif $_l2.menu_url|substr:0:1 === '#'}{$_l2.menu_url}{else}{$jamroom_url}/{$_l2.menu_url}{/if}" onclick="{$_l2.menu_onclick}" >{$_l2.menu_title}</a></li>
            {/foreach}
            </ul>
            {/if}
        </li>
        {/foreach}
    </ul>
    {/if}
</li>
{/foreach}

You can adjust it by passing it first into your own smarty function

Docs: "Defining your own SMARTY function"
https://www.jamroom.net/the-jamroom-network/documentation/module-developer-guide/1569/defining-your-own-smarty-function

So it becomes
{xxYourCustom_something list=$_list assign="_list"}
{foreach $_list as $_l0}
....... the same stuff as it was before
{/foreach}

So in your custom function you accept the current list and adjust as necessary.

OR you could inject via other listener parameters before the template is reached.
TiG
TiG
@tig
6 years ago
184 posts
Michael

Given this appears to be best addressed with template overrides and smarty functions (rather than a listener) I will adopt your approach. (Have written quite a few smarty functions at this point.) Your approach will provide plenty of options for future menu refinements (if need be). It also offers the option to encapsulate menu item changes within the modules which deliver the functionality.

Thanks,
TiG


--
TiG

Tags