Page 1 of 1

Have an empty/blank menu display static text?

Posted: Tue Jun 06, 2017 3:12 am
by michaywood
I have a menu item within my page that links to some specific pages as they are activated. However, before the first page is activated, the website is a little missing on that page. Is there a way to display some text like 'no pages active yet' ? Here is my navigator template code below. I assume I need to add an {else}<span>no pages active yet</span> or similar somewhere, but haven't figured it out. Any ideas?

Thanks

Code: Select all

{function name=sub_menu depth=1}{strip}
  {foreach $data as $node}
    {* setup classes for the anchor and list item *}
    {assign var='aclass' value='button'}

    {if $node->current}
      {* this is the current page *}
      {assign var='aclass' value=$aclass|cat:'active'}
    {/if}

    {* build the menu item node *}
    {if $node->type == 'sectionheader'}
      <li class='sectionheader'><span>{$node->menutext}</span>
        {if isset($node->children)}
          {sub_menu data=$node->children depth=$depth+1}
        {/if}
      </li>
    {else if $node->type == 'separator'}
      <li class='separator'><hr class='separator'/></li>
    {else}
      {* regular item *}
        <a class="{$aclass}" href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if} aria-label="{$node->menutext}">{$node->menutext}</a
        {if isset($node->children)}
          {sub_menu data=$node->children depth=$depth+1}
        {/if}
    {/if}
  {/foreach}

{/strip}{/function}

{if isset($nodes)}
{sub_menu data=$nodes depth=0}
{/if}

Re: Have an empty/blank menu display static text?

Posted: Tue Jun 06, 2017 12:57 pm
by velden
Not exactly clear as how it should work but perhaps you can try:

Code: Select all

....
{/strip}{/function}

{if isset($nodes)}
{sub_menu data=$nodes depth=0}
{else}
no pages active yet
{/if}

Re: Have an empty/blank menu display static text?

Posted: Tue Jun 06, 2017 1:04 pm
by michaywood
Thanks. I had given that a try and just tested again with a copy/paste of your code (in case I had a typo in my example) but it doesn't output anything onto the page. Still just blank?

also: for the thread, I saw there's a typo on my closing </a tag. this was fixed adding the >.

edit: Any other ideas on how to display text when the menu is empty? Or maybe do I need to not do it within the navigator template, but within the page content instead where the menu is called? can that be done/easier?

Re: Have an empty/blank menu display static text?

Posted: Tue Jun 06, 2017 1:35 pm
by scooper
Can you use count? Something like

Code: Select all


{if isset($nodes) && $nodes|count gt 0}
 {sub_menu data=$nodes depth=0}
{else}
 nothing to see here.
{/if}


[solved] Re: Have an empty/blank menu display static text?

Posted: Tue Jun 06, 2017 3:01 pm
by michaywood
Thanks for the idea, I had not tried that one. It didn't work on first attempt, but then I realized my page alias had changed, so the menu wasn't showing what it should show anyways. Once I fixed that in my page content, then added

Code: Select all

&& $nodes|count gt 0
to the navigation menu, the else statement now display if no pages are active!

Thanks all for the help! Excited to have this to be able to deploy in other scenarios as well to still have content when none exists yet

Re: Have an empty/blank menu display static text?

Posted: Tue Jun 06, 2017 5:55 pm
by calguy1000
Use: {if !empty($nodes)} ... it's simpler and faster.

[solved] Re: Have an empty/blank menu display static text?

Posted: Tue Jun 06, 2017 5:59 pm
by michaywood
thanks @calguy1000 . made the update and working great