Forums / Setup & design / 3.4 - how to make right hand toolbar content section dependent?

3.4 - how to make right hand toolbar content section dependent?

Author Message

steve walker

Thursday 08 July 2004 1:06:41 am

Hi there,

I have a question regarding toolbar content customisation that doesnt seem to be in the docs or other threads.

We want to create a right hand toolbar that will display content dependent on the section it is in. So, if you go to the services section it lists past projects, or on the home page it shows latest news etc.

I thought the best way of doing this is to setup seperate folders (hidden from navigation) for each of these sections that contain the toolbar data - and then have a bit of script in the fetch of the toolbar thats says:

'if this section = 'services' then node_id=90' for example... so the node_id is dynamic dependent on the section you are in.

Does this seem the right approach, and does anyone have any experience of this sort?

Many thanks, Steve.

http://www.oneworldmarket.co.uk

Alex Jones

Thursday 08 July 2004 7:24:45 am

That's the approach I would take. I have successfully used similar setups for section-dependent displays.

Alex
bald_technologist on the IRC channel: #eZpublish
http://www.agrussell.com :: http://www.cuttingedge.com

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

steve walker

Thursday 08 July 2004 7:34:41 am

Alex,

Cheers for the reply - I dont suppose you have any code snippets you could copy/paste into here at all? The long 'if then' statement especially?

Thanks, Steve.

http://www.oneworldmarket.co.uk

Alex Jones

Thursday 08 July 2004 9:02:38 am

Well, you can make it much easier using a switch/case. Something along the lines of:

{switch name=Toolbar match=$DesignKeys:used.section}
  {case match=1}
    <p>Show this content only on the main page</p>
  {/case}	  
  {case match=4}
    <p>Show this for the Services pages</p>
  {/case}	    
  {case match=6}
    <p>Show News stuff here</p>
  {/case}	  
  {case in=array(1,6)}
    <p>Show this on both the main page and the News page, but NOT the Services page</p>
  {/case}
  {case}
    <p>Show this if the page is in a section that doesn't match any of the above.</p>
  {/case}
{/switch}

For this example, let's say the main section of the site has a Section ID of 1, the Services Section has an ID of 4, and the News section an ID of 6. The switch statement will match each of the cases against <i>$DesignKeys:used.section</i> which is the section id of the currently viewed page.

Switch Documentation: http://ez.no/ez_publish/documentation/development/libraries/ez_template/functions/switch
Template Variables Set by eZ publish: http://ez.no/content/search?SearchText=designkeys

Does this help?

Alex
bald_technologist on the IRC channel: #eZpublish
http://www.agrussell.com :: http://www.cuttingedge.com

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

steve walker

Thursday 08 July 2004 9:21:41 am

Alex,

Thankyou very much! This is a great help.

I was worried that this approach might make for bloaty code in the right hand toolbar tpl, but I guess as it'll be cached it shouldnt make any difference?

I'm going to start building out the backend of this site over next week or two so will let you know how I get on.

Thanks again for the tips.

Steve.

http://www.oneworldmarket.co.uk

Alex Jones

Thursday 08 July 2004 9:46:27 am

You should be fine using this as the pages will indeed by cached. :)

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

steve walker

Friday 23 July 2004 7:36:15 am

Hi!

Carrying on this thread for a sec: the code works great! I am using it to switch between two sections to run different navigation menus. The code works fine if I put:

{switch name=Toolbar match=$DesignKeys:used.section}
{case match=5}

home section

{/case}
{case}

all other sections

{/case}
{/switch}

However, as soon as I add the navigation code between the {case}{/case} tags, it all goes to pot:(

{switch name=Toolbar match=$DesignKeys:used.section}
{case match=5}

home section

{/case}
{case}

<div id="leftmenu">
<div id="leftmenu-design">

<h3 class="hide">{"Left sub menu"|i18n("design/base")}</h3>

{section show=and( is_set( $module_result.path[1] ), is_set( $module_result.node_id ) )}
{let root_node=fetch( content, node, hash( node_id, 2 ) )
submenu=fetch( content, list, hash( parent_node_id, $module_result.path[1].node_id,
class_filter_type, include,
class_filter_array, ezini( 'MenuContentSettings', 'LeftIdentifierList', 'menu.ini' ),
sort_by, $root_node.sort_array ) )}
<ul>
{section var=menu loop=$submenu}
<li class="menu-level-0"><a href={$menu.url_alias|ezurl}>{$menu.name|shorten( 25 )}</a></li>
{/section}

{section show=$submenu|count}
<li class="menu-level-0"></li>
{/section}
</ul>

<div class="breakall"></div>

{/let}
{/section}

</div>
</div>


{/case}
{/switch}

Are the section tags within the navigation mucking this up? Is there a limit to the type of code you can put between the 'case' tags?

I know the navigation code is OK as its straight from the sub_left.tpl file.

Any input greatly received!

Steve.

http://www.oneworldmarket.co.uk

Alex Jones

Friday 23 July 2004 2:46:59 pm

What actually happens when you insert the navigation code? Does it display anything?

As far as I know, there isn't any constraint to the amount of code within case tags, nor are there any constrains concerning sections.

Make sure that your variables were created within a <i>let</i> tag encasing this code. If you copied this from a different part of the page, you may need to declare <i>menu</i>...

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

steve walker

Monday 26 July 2004 7:50:30 am

Alex,

Hi there!

When I insert the navigation code, nothing happens... the <div> information for the first korizontal line before the navigation list is displayed is there, but thats it - so it looks like it breaks in the navigation code.

I've tried to simplify the code so that there are 'let' tags around the code within the 'case' switches so I now have:

{switch name=Toolbar match=$DesignKeys:used.section}
{case match=5}
<p>Show this content only on the main page</p>
{/case}
{case}

{let root_node=fetch( content, node, hash( node_id, 2 ) )
submenu=fetch( content, list, hash( parent_node_id, $module_result.path[1].node_id,
class_filter_type, include,
class_filter_array, ezini( 'MenuContentSettings', 'LeftIdentifierList', 'menu.ini' ),
sort_by, $root_node.sort_array ) )}
<ul>
{section var=menu loop=$submenu}
<li class="menu-level-0"><a href={$menu.url_alias|ezurl}>{$menu.name|shorten( 25 )}</a></li>
{/section}

{section show=$submenu|count}
<li class="menu-level-0"></li>
{/section}
</ul>

<div class="breakall"></div>
{/let}

{/case}
{/switch}

Still not working for the second case instance... Any ideas on this? I dont think I need to add thed 'menu' tage as I'm replacing the sub_left.tpl menu template file?

Cheers, Steve.

http://www.oneworldmarket.co.uk

Alex Jones

Wednesday 28 July 2004 1:00:30 pm

Hrrrm, I'm not spotting anything at the moment. I'm still not sure if <i>menu</i> has actually been declared anywhere though. Have you turned on debugging to see if it can provide you additional information? If you have turned it on, and nothing is returned, use the following bit of code to see if the second case statement is being triggered at all:

{switch name=Toolbar match=$DesignKeys:used.section}
{case match=5}
<p>Show this content only on the main page</p>
{/case}
{case}
** Test 1 **
{let root_node=fetch( content, node, hash( node_id, 2 ) )
submenu=fetch( content, list, hash( parent_node_id, $module_result.path[1].node_id,
class_filter_type, include,
class_filter_array, ezini( 'MenuContentSettings', 'LeftIdentifierList', 'menu.ini' ),
sort_by, $root_node.sort_array ) )}
<ul>
{section var=menu loop=$submenu}
<li class="menu-level-0"><a href={$menu.url_alias|ezurl}>{$menu.name|shorten( 25 )}</a></li>
{/section}

{section show=$submenu|count}
<li class="menu-level-0"></li>
{/section}
</ul>

<div class="breakall"></div>
{/let}

** Test 2 **

{/case}
{/switch}

When you test, you should see ** Test 1 ** and ** Test 2 ** show up in your page. That will at least ensure that the switch statement isn't the issue.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

steve walker

Friday 30 July 2004 10:01:36 am

Alex,

Cheers for your input.

Firstly the switch code is great - using your test code gives fine results, so that isnt the problem.

However, with the code:

{switch name=Toolbar match=$DesignKeys:used.section}
  {case match=5}
    <p>Show this content only on the main page</p>
  {/case}	  
  {case}
   <div id="leftmenu">
<div id="leftmenu-design">

<h3 class="hide">{"Left sub menu"|i18n("design/base")}</h3>

{section show=and( is_set( $module_result.path[1] ), is_set( $module_result.node_id ) )}
{let root_node=fetch( content, node, hash( node_id, 2 ) )
     submenu=fetch( content, list, hash( parent_node_id, $module_result.path[1].node_id,
                                         class_filter_type, include,
                                         class_filter_array, ezini( 'MenuContentSettings', 'LeftIdentifierList', 'menu.ini' ),
                                         sort_by, $root_node.sort_array ) )}
    <ul>
    {section var=menu loop=$submenu}
        <li class="menu-level-0"><a href={$menu.url_alias|ezurl}>{$menu.name|shorten( 25 )}</a></li>
    {/section}

    {section show=$submenu|count}
    <li class="menu-level-0"></li>
    {/section}
    </ul>

    <div class="breakall"></div>

{/let}
{/section}

</div>
</div>

  {/case}
{/switch}

I get these messages:

Error: eZTemplate Jul 30 2004 18:59:29

Unknown template variable 'root_node' in namespace ''
Error: eZTemplate @ design/mediacontacts/templates/menu/sub_left.tpl:21[4] Jul 30 2004 18:59:29

Unknown template variable 'submenu' in namespace ''
Error: eZTemplate @ design/mediacontacts/templates/menu/sub_left.tpl:25[4] Jul 30 2004 18:59:29

Unknown template variable 'submenu' in namespace ''

All referring to the template in question.

Do I have to declare any variables outside of the switch statements? Would seem a bit limiting if I do....

Regards, Steve.

http://www.oneworldmarket.co.uk

Alex Jones

Tuesday 03 August 2004 9:11:36 am

Hrrrm, i'm not sure what would be causing the problem. The variables appear to be declared properly... You oculd try declaring them earlier, it wouldn't hurt anything, but as you said, it seems pretty silly to have to do that. If I can think of anything else, I'll post it.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

steve walker

Tuesday 03 August 2004 12:44:25 pm

Alex,

Many thanks for the input.

Do the Ez crew have any ideas on these error messages and why this code (which within the case statements is simply a copy/paste of the sub_left template code) is mucking up the case execution?

Thanks, Steve.

http://www.oneworldmarket.co.uk

steve walker

Wednesday 04 August 2004 12:28:39 am

Alex,

Managed to get this working, but by using 'section show' rather than switch. Code that switches between the different menu's is:

{section show=eq($DesignKeys:used.section,5)}
 
 <div id="leftmenu">
<div id="leftmenu-design">

<h3 class="hide">{"Left sub menu"|i18n("design/base")}</h3>

{section show=and( is_set( $module_result.path[1] ), is_set( $module_result.node_id ) )}
{let root_node=fetch( content, node, hash( node_id, 2 ) )
     submenu=fetch( content, list, hash( parent_node_id, 2,
                                         class_filter_type, include,
                                         class_filter_array, ezini( 'MenuContentSettings', 'LeftIdentifierList', 'menu.ini' ),
                                         sort_by, $root_node.sort_array ) )}
    <ul>
    {section var=menu loop=$submenu}
        <li class="menu-level-0"><a href={$menu.url_alias|ezurl}>{$menu.name|shorten( 25 )}</a></li>
    {/section}

    {section show=$submenu|count}
    <li class="menu-level-0"></li>
    {/section}
    </ul>

    <div class="breakall"></div>

{/let}
{/section}

</div>
</div>
 
{section-else}

<div id="leftmenu">
<div id="leftmenu-design">

<h3 class="hide">{"Left sub menu"|i18n("design/base")}</h3>

{section show=and( is_set( $module_result.path[1] ), is_set( $module_result.node_id ) )}
{let root_node=fetch( content, node, hash( node_id, 2 ) )
     submenu=fetch( content, list, hash( parent_node_id, $module_result.path[1].node_id,
                                         class_filter_type, include,
                                         class_filter_array, ezini( 'MenuContentSettings', 'LeftIdentifierList', 'menu.ini' ),
                                         sort_by, $root_node.sort_array ) )}
    <ul>
    {section var=menu loop=$submenu}
        <li class="menu-level-0"><a href={$menu.url_alias|ezurl}>{$menu.name|shorten( 25 )}</a></li>
    {/section}

    {section show=$submenu|count}
    <li class="menu-level-0"></li>
    {/section}
    </ul>

    <div class="breakall"></div>

{/let}
{/section}

</div>
</div>

{/section}

I need to use this in more complex situations soon though, hope it scales up ok...

Steve,

http://www.oneworldmarket.co.uk

steve walker

Wednesday 04 August 2004 12:39:09 am

Just talking about the more complex situations I just mentioned, is it possible to perform multiple matches, something along the lines of:

{section show=eq($DesignKeys:used.section,5)}
 
here we show section 5

{or section show=eq($DesignKeys:used.section,4)}

here we show section 4
 
{section-else}

here we show everything else

{/section}

Thanks, Steve.

http://www.oneworldmarket.co.uk

Alex Jones

Wednesday 04 August 2004 8:48:04 am

Glad you got it working! I am not aware of a way to do the multiple section shows like you demonstrated, I believe that is the purpose of the switch functionality (right back to where we started!) :(

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

steve walker

Wednesday 04 August 2004 9:18:34 am

Cheers Alex!

Could I ask an Ez Crew coder to point out why the switching code earlier in this thread isnt working.

As has been said, for this simple binary situation using sections is fine, but I need to use more complex switching very soon.

Would appreciate resolving this little conundrum.

Thanks, Steve.

http://www.oneworldmarket.co.uk

Bård Farstad

Monday 09 August 2004 3:41:03 am

Steve,

The reason why the switching earlier doesn't work is that you try to use the or operator as a function which takes section as an argument/parameter. This is not supported.

You can use a normaly switch for this:

{switch match=$DesignKeys:used.section}
{case match=4}
    This is in section 4.
{/case}
{case match=3}
    This is in section 3.
{/case}
{case match=2}
    This is in section 2.
{/case}
{case}
    This is the default case, i.e. not in section 2,3 or 4.
{/case}
{/switch}

--bård

Documentation: http://ez.no/doc

steve walker

Monday 09 August 2004 4:07:02 am

Bard,

Thankyou for your response.

I'm still not completely clear on this though - are you saying it is beyond the scope of the switch function to be able change the menu displayed dependent on the section? Is what I am trying to achieve feasable?

Regards, Steve.

http://www.oneworldmarket.co.uk

Bård Farstad

Monday 09 August 2004 4:22:30 am

Steve,

no, not at all. We use a switch to do excactly this here on ez.no. A switch is very well suited to show e.g. a menu/graphigs dependant on which section you are in on the site.

--bård

Documentation: http://ez.no/doc