Jump to:

22977 Posts in 11806 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » nested control problem

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1605 Views
  • SSadmin
    Avatar
    Community Member
    90 Posts

    nested control problem Link to this post

    hey, all.
    i am working on a project that needs to do some nested control stuff.

    Site Tree
    + product holder (ProductHolderType)
    -Product A (ProductPage Type)
    -Product B (ProductPage Type)
    -term and condition (Page Type)

    The outcome i wanna achieve is on my ProductHolder, ProductA,B and Term and condition Page show side bar for secondary-level navigation.

    i created a sideNav.ss in the include file.

       <% control Menu(2) %>

                 <% if LinkOrSection = section %>
                    <% if Children %>
                      <h4>
                         $MenuTitle.XML
                       </h4>
                      <ul class="sub">
                         <li>
                            <ul class="roundWhite">
                               <% control Children %>
                                  <li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode levelb">$MenuTitle.XML</a></li>
                               <% end_control %>
                            </ul>
                         </li>
                      </ul>
                     <% end_if %>
                <% end_if %>
             </li>
       <% end_control %>

    The ProductHolder, and ProductPage type works fine.

    Since i have already got lots of different page types, thought it will be neasty for creating a new Page type for using the side bar there.
    So i wanna achieve If the normal Page under the ProductHolder -> show sidebar. otherwise dont show.

    i did something like    <% control Parent %>
             
             <% if ClassName = ProductHolder %>

             <% include SideNav %>
             
             <% end_if %>
             
             <% end_control %>

    i dont why the code in the SideNav.ss cannot be executed. maybe they nested control there?!

    Another alternative way:
    try to use php code logic to do the if statement and renderwith the template in the include file.
    was doing someting like:

    public function includeSideNav(){
          Debug::show($this->Parent()->ClassName);
          if($this->Parent()->ClassName=="ProductHolder")
             {
                //display the outcomes
                return Director::$this->renderWith("Includes/SideNav.ss");
                }
          }

    But seems doesnt work. error message[stat failed for Includes/SideNav.ss]

    Anyone can help
    Thanks in advanced

  • hive.net.au
    Avatar
    Community Member
    40 Posts

    Re: nested control problem Link to this post

    Hi SSAdmin

    The last section is erroring becuase you are calling the following wrong
    return Director::$this->renderWith("Includes/SideNav.ss");
    should be
    return Director::$this->renderWith(array("SideNav"));

    That should resolve your stat problem, let me know how you go

    As for your orginal idea i can not see where it is going wrong, have tried using the ?showtemplate=1 to see what is going on?

  • SSadmin
    Avatar
    Community Member
    90 Posts

    Re: nested control problem Link to this post

    hey, hive.net.au

    Thanks for your timely reply.

    i have changed the return Director::$this->renderWith("Includes/SideNav.ss") to Director::$this->renderWith(array("SideNav"));
    It works perfectly.

    I was still confused how the frist approach doesnt show anything.
    So i did run ?templeshow=1;

    The view code is listed following:
    29       <div class="aside">
    30          
    31       
    32 SSVIEWER;
    33 array_push($itemStack, $item); if($loop = $item->obj("Parent")) foreach($loop as $key => $item) { ;
    34 $val .= <<<SSVIEWER
    35
    36
    37
    38 SSVIEWER;
    39 if($item->XML_val("ClassName",null,true) == "ProductHolder") { ;
    40 $val .= <<<SSVIEWER
    41
    42
    43 <!-- include C:/wamp/www/clicknz/themes/clicknz/templates/Includes/SideNav.ss -->
    44
    45    
    46 SSVIEWER;
    47 array_push($itemStack, $item); if($loop = $item->obj("Menu", array("2"))) foreach($loop as $key => $item) { ;
    48 $val .= <<<SSVIEWER
    49
    50
    51              
    52 SSVIEWER;
    53 if($item->XML_val("LinkOrSection",null,true) == "section") { ;
    54 $val .= <<<SSVIEWER
    55
    56                 
    57 SSVIEWER;
    58 if($item->hasValue("Children")) { ;
    59 $val .= <<<SSVIEWER
    60
    61                   <h4>
    62                      
    63 SSVIEWER;
    64 $val .= $item->obj("MenuTitle",null,true)->XML_val("XML",null,true) ;
    65 $val .= <<<SSVIEWER
    66
    67                    </h4>
    68                   <ul class="sub">
    69                      <li>
    70                         <ul class="roundWhite">
    71                            
    72 SSVIEWER;
    73 array_push($itemStack, $item); if($loop = $item->obj("Children")) foreach($loop as $key => $item) { ;
    74 $val .= <<<SSVIEWER
    75
    76                               <li><a href="
    77 SSVIEWER;
    78 $val .= $item->XML_val("Link",null,true) ;
    79 $val .= <<<SSVIEWER
    80 " title="Go to the
    81 SSVIEWER;
    82 $val .= $item->obj("Title",null,true)->XML_val("XML",null,true) ;
    83 $val .= <<<SSVIEWER
    84 page" class="
    85 SSVIEWER;
    86 $val .= $item->XML_val("LinkingMode",null,true) ;
    87 $val .= <<<SSVIEWER
    88 levelb">
    89 SSVIEWER;
    90 $val .= $item->obj("MenuTitle",null,true)->XML_val("XML",null,true) ;
    91 $val .= <<<SSVIEWER
    92 </a></li>
    93                            
    94 SSVIEWER;
    95 } $item = array_pop($itemStack); ;
    96 $val .= <<<SSVIEWER
    97
    98                         </ul>
    99                      </li>
    100                   </ul>
    101                 
    102 SSVIEWER;
    103 } ;
    104 $val .= <<<SSVIEWER
    105
    106             
    107 SSVIEWER;
    108 } ;
    109 $val .= <<<SSVIEWER
    110
    111          </li>
    112    
    113 SSVIEWER;
    114 } $item = array_pop($itemStack); ;
    115 $val .= <<<SSVIEWER
    116
    117 <!-- end include C:/wamp/www/clicknz/themes/clicknz/templates/Includes/SideNav.ss -->
    118
    119
    120 SSVIEWER;
    121 } ;
    122 $val .= <<<SSVIEWER
    123
    124
    125
    126 SSVIEWER;
    127 } $item = array_pop($itemStack); ;
    128 $val .= <<<SSVIEWER
    129
    130
    131 </div>   <!--close aside-->

    Seems the loop has been executed to me. but why nothing displayed afterwards. The Term conditions and ProductA are in the same level, which means if it can be dispalyed on ProductA page should be display on normal page as well using same inlcude file( SideNav.ss ). Any ideas?

    Anyway.thanks for your help hive.net.au
    /cheer Apperciated XD

    1605 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.