Have an empty/blank menu display static text?

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Locked
michaywood
Power Poster
Power Poster
Posts: 280
Joined: Thu Apr 15, 2010 12:27 am
Location: Georgia

Have an empty/blank menu display static text?

Post 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}
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3479
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

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

Post 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}
michaywood
Power Poster
Power Poster
Posts: 280
Joined: Thu Apr 15, 2010 12:27 am
Location: Georgia

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

Post 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?
scooper
Forum Members
Forum Members
Posts: 242
Joined: Fri Dec 09, 2005 12:36 pm
Location: Marlow, UK

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

Post 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}

michaywood
Power Poster
Power Poster
Posts: 280
Joined: Thu Apr 15, 2010 12:27 am
Location: Georgia

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

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

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

Post by calguy1000 »

Use: {if !empty($nodes)} ... it's simpler and faster.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
michaywood
Power Poster
Power Poster
Posts: 280
Joined: Thu Apr 15, 2010 12:27 am
Location: Georgia

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

Post by michaywood »

thanks @calguy1000 . made the update and working great
Locked

Return to “Layout and Design (CSS & HTML)”