parent_class and is_container

Author Message

Pascal France

Friday 18 August 2006 12:24:30 am

Hi,

I would like to define if the parent of a node is a folder, so, to to that I would like to define if this parent_node (or maybe parent_class) is a container.

Now, my code is:

{let enfant_1=fetch(content,list,hash(parent_node_id,$:item.node_id,
                    class_filter_type, "include",
                    class_filter_array, ezini( 'MenuContentSettingsMPT', 'TopIdentifierList', 'menu.ini' ) ,
                    sort_by,$base.sort_array))}
    <li>{* li_1 *}
        <a {section show=$enfant_1|count|gt(0)}{/section} href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a>

and I would like to include something like that:

    <li>{* li_1 *}
        {if eq(<parent_node or parent_class>.is_container, true())}
            something here
        {else}
        <a {section show=$child_check|count|gt(0)}{/section} href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a>
        {/if}

Regards

Pascal

Ce qui embellit le désert c'est qu'il cache un puits... quelque part... (A. de Saint-Exupéry) - http://luxpopuli.fr/eZ-Publish

Pascal France

Friday 18 August 2006 8:16:58 am

Hi,

Well... I'm looking for another solution with the class identifier.
The initial code is:

{section loop=fetch(content,list,hash(parent_node_id,$top_cat,
                class_filter_type, "include",
                class_filter_array, ezini( 'MenuContentSettingsMPT', 'TopIdentifierList', 'menu.ini' ) ,
                sort_by,$base.sort_array))}
{let child_check=fetch(content,list,hash(parent_node_id,$:item.node_id,
                    class_filter_type, "include",
                    class_filter_array, ezini( 'MenuContentSettingsMPT', 'TopIdentifierList', 'menu.ini' ) ,
                    sort_by,$base.sort_array))}
    <li>{* li_1 *}
        <a {section show=$child_check|count|gt(0)}{/section} href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a>

I want that if $child_check class is a folder class, then it won't be a link.

So, I begin to find the class identifier of $child_check

    <li>{* li_1 *}
        {def $aaa1=$:item.object.class_identifier}

...and this works fine.
According with the "is_class" doc I have tried:

    <li>{* li_1 *}
        {def $aaa1=$:item.object.class_identifier}
        {section show=$child_check|count|gt(0)}{/section}
        {if is_class('dossier_assemblee_generale', $aaa1)}
            {$:item.name}
        {else}
        <a href={concat("/content/view/full/",$:item.node_id,"/")|ezurl}>{$:item.name}</a>
        {/if}

But this doesn't work.

Pascal

Ce qui embellit le désert c'est qu'il cache un puits... quelque part... (A. de Saint-Exupéry) - http://luxpopuli.fr/eZ-Publish

Claudia Kosny

Friday 18 August 2006 12:05:10 pm

Hello Pascal,

Unfortunately I am not exactly sure what exactly you try to do, therefore some code examples below which hopefully help you further.

First a remark to your code though:
You use

 {section show=$child_check|count|gt(0)}{/section}

Both in your first and in your second example. But this will not do anything at all as you have no code between the opening anf the closing of the section. The usage for section show is roughly like this:

{section show=<some condition here>}
 this code is only executed when the condition in show is true
{section-else}
this code is only executed when the condition in show is false
{/section}

(The else part is not required)

If the code samples below do not help you please post again but this time without any code. Just explain in short sentences what exaxtly try to achieve.

Here my examples. Please check the comments at each foreach loop as this explains, what exactly we are checking for. Also you have to adapt the fetch function in the beginning to yours.

{* fetch the main nodes *}
{def $main_nodes = fetch(content,tree,hash(parent_node_id,2))}

{* check whether any of these nodes is a container *}
{foreach $main_nodes as $main_node}
 {if $main_node.object.content_class.is_container}
  {$main_node.name} is a container <br />
 {else}
  {$main_node.name} is NOT a container <br />
 {/if}
{/foreach}
<br />
<br />

{* check whether any of these nodes contains any child nodes *}
{foreach $main_nodes as $main_node}
 {if $main_node.children_count|gt(0)}
  {$main_node.name} is a container <br />
 {else}
  {$main_node.name} is either not a container or is a container that has no children at the moment<br />
 {/if}
{/foreach}
<br />
<br />

{* check whether any of these nodes has a class identifier defined in 
   array $folderClasses, this array can also come from an ini file *}
{def $folderClasses = array('folder', 'specialfolder')}
{foreach $main_nodes as $main_node}
 {if $folderClasses|contains($main_node.class_identifier)}
  {$main_node.name} is a folderclass <br />
 {else}
  {$main_node.name} is NOT a folderclass <br />
 {/if}
{/foreach}
<br />
<br />

{* check whether the parent node of any one of these nodes has a 
  class identifier defined in array $folderClasses *}
{* we KNOW that the parentnode is a container as otherwise it could
   not contain children but maybe we want to check for somehting  else *}
{foreach $main_nodes as $main_node}
 {if $folderClasses|contains($main_node.parent.class_identifier)}
  the parent of {$main_node.name} is a folderclass <br />
 {else}
  the parent of {$main_node.name} is NOT a folderclass <br />
 {/if}
{/foreach}

Greetings from Luxembourg

Claudia

Pascal France

Sunday 20 August 2006 1:00:19 am

Hi Claudia,

Thank you very much !

Regards

Pascal

Ce qui embellit le désert c'est qu'il cache un puits... quelque part... (A. de Saint-Exupéry) - http://luxpopuli.fr/eZ-Publish

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