How do I use the section id in pagelayout.tpl?

Author Message

Nathan Kelly

Thursday 23 June 2005 7:49:28 pm

I have a two level navigation bar that has to change from 1 level to 2 level depending on what section of the site a visitor is currently in, for example, if a visitor is on the homepage the navigation consists of only the top level, but if they are on any other page the navigation will consist of both the top level nav and a second level nav.

My current pagelayout.tpl contains the following code:-

{* Loop through the top level navigation and output it. *}
			
{let mainMenu=treemenu( $module_result.path, 
		$module_result.node_id,
		array('folder'), 0, 1 )}
			
		<div id="main-nav">
		
			<div class="retainer">
				<ul>
	{* Here is the loop, class indexed by node_ID number. *}
	{section var=menu loop=$mainMenu}
      					<li class="node-{$menu.id}"><a href={$menu.item.url_alias|wash|ezurl}>{$menu.item.text|wash}</a></li>

	{/section}
				</ul>
			</div>
			
		</div>
{/let}

{* Check if we need the sub-nav *}

{let subNav='yes'}
	{section show=$subNav|eq('yes') }

		{* If we are in the right section loop through the second level navigation and output it. *}
		
    		{let subMenu=treemenu($module_result.path, 
                        		$module_result.node_id,
			array('folder'), 1, 1 )}

		<div id="sub-nav">
		
			<div class="retainer">			
				<ul>

				{* Here is the loop, class indexed by ID number. *}

				{section var=menu loop=$subMenu}	
      					<li class="node-{$menu.id}"><a href={$menu.item.url_alias|wash|ezurl}>{$menu.item.text|wash}</a></li>

				{/section}

				</ul>
			</div>
		
		</div>

		{/let}

	{* If we are not in the right section ignore the sub-nav and replace it with nothing *}
	{section-else}

	{/section}
{/let}

The reason i need to remove the sub-nav if it's not needed in due to the fact that i need to get rid of any redundant HTML code (particularly the empty <ul> tags for validation reasons).

My problem is I am unsure as to the syntax of the following.

From the Documentation:-
>How do I access the section id in pagelayout.tpl?
>One way is via $DesignKeys:used.section.
>$DesignKeys is a way to know the section you are actually in.
>In order to retrieve a section assigned to a current content object you can use let sectionID=first_set($node.object.section_id,0).

Obviousley looking at my code above you will notice i have setup my condition as follows:-

{let subNav='yes'}
	{section show=$subNav|eq('yes') }

	*some html etc.*

	{section-else}
	
	*some html etc.*

	{/section}
{/let}

My question is how can I use the code from the documentation within the code above to make this work?

Any help is much appreciated.

Pardon me while I burst into flames...

Daniel Beyer

Friday 24 June 2005 11:32:03 am

Hi,

if you want to keep your existing code try this:

{let subNav='yes'}

  {switch match=$module_result.section_id}
    {case match=1}
      {set subNav='no'}
    {/case}

    {case match=2}
      {set subNav='yes'}
    {/case}

    {case}
      {* This is the case if nothing is in $module_result.section_id - or the sectionID was not mentioned above...  *}
    {/case}
  {/switch}

	{section show=$subNav|eq('yes') }

	*some html etc.*

	{section-else}
	
	*some html etc.*

	{/section}
{/let}

Personaly I prefer boolean instead of 'yes' and 'no'. But this will work too...

To do that with boolean values, try that:

{let subNav=true()}

  {switch match=$module_result.section_id}
    {case match=1}
      {set subNav=false()}
    {/case}

    {case match=2}
      {set subNav=true()}
    {/case}

    {case}
      {* This is the case if nothing is in $module_result.section_id - or the sectionID was not mentioned above...  *}
    {/case}
  {/switch}

	{section show=$subNav }

	*some html etc.*

	{section-else}
	
	*some html etc.*

	{/section}
{/let}

Refer to this docs:
-http://ez.no/ez_publish/documentation/development/libraries/ez_template/functions/switch
-http://ez.no/ez_publish/documentation/customization/custom_design/template_variables_set_by_ezpublish

Hope this helps...
...and have a nice weekend with trying it ;)

Daniel Beyer
_________________________________
YMC AG
Kreuzlingen, Switzerland
web: www.ymc.ch
____________________________________

Nathan Kelly

Sunday 26 June 2005 5:32:12 pm

Hi Daniel,

thankyou very much for your suggestions, I have used the second one that uses Boolean values an it has worked fine.

I have one more quick question, how can I use this with multiple sections? For example if all of my web pages belong to section 1 exept for the home page and one other page do simply add an extra case, or is it more complex than that?

or can I do something like the following?

    {case match=1,4}
      {set subNav='no'}
    {/case}

Like build an array with those section id's in it?

Thanks again for your help!

Pardon me while I burst into flames...

Daniel Beyer

Tuesday 28 June 2005 9:00:11 am

Hi,

in this case forget about the {switch} thing. It would be nicer to do it with a simple {section show} (or a {if} if you're using eZ 3.6.0 or up):

{let subNav=false()
     showSubNavSections=array(1,3,7,4}

  {section show=$showSubNavSections|contains($module_result.section_id)}
      {set subNav=true()}
  {/section}

	{section show=$subNav }

	*some html etc.*

	{section-else}
	
	*some html etc.*

	{/section}
{/let}

Or even better do only one {section show} for this:

{let showSubNavSections=array(1,3,7,4}

	{section show=$showSubNavSections|contains($module_result.section_id)}

	*some html etc.*

	{section-else}
	
	*some html etc.*

	{/section}
{/let}

Refer to this docs:
http://ez.no/ez_publish/documentation/incoming/appendices/appendix_e_ez_publish_template_operators
http://ez.no/ez_publish/documentation/incoming/appendices/appendix_f_ez_publish_template_functions

Daniel Beyer
_________________________________
YMC AG
Kreuzlingen, Switzerland
web: www.ymc.ch
____________________________________

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.