Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » How to use <% control %> and <% if %>

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1467 Views
  • Tkop
    Avatar
    28 Posts

    How to use <% control %> and <% if %> Link to this post

    I'm having problems using the controllers. I can get it working for single variable returns
    see BannerImg (I'm using it as text for now just to test) below but am unable to get
    getChildrenof(title) to work. Below are the portions of the *.code and Layout/*.ss files
    and the error I get. I've gone through the all the tuorials and the documantation on the site.
    Also I get errors when I try to put Debug::message("hello") and Debug::show($variable)
    in either the *.code or *.ss file how are you suposed to call them?

    ----------------------------------------------------------------------------------------------------------------
    SectionHolder.php
    class SectionHolder_Controller extends Page_Controller {
    function BannerImg() {
    return $this->BannerImg;
    }
    function getChildrenOf($searchtitle) {
    $data = DataObject::get($searchtitle, "ShowInMenus = 1");
    return $data->Children();
    }
    }
    -------------------------------------------------------------------------
    SectionMenu.ss
    <% if Menu(2) %>
    <p>$BannerImg</p>
    <ul id="Menu2">
    <% control Menu(2) %>
    <div id="subh2"> <div class="gla-r"> <div class="gla-l">
    $MenuTitle
    </div></div></div>
    <% control getChildrenOf($Title) %>
    <li class="$LinkingMode"><a href="$Link" title="Go to the $Title page">$MenuTitle</a></li>
    <% end_control %>
    <% end_control %>
    </ul>
    <% end_if %>

    -------------------------------------------------------------------------
    error I get:
    Parse error: syntax error, unexpected '}' in /tmp/silverstripe-cache/.cache.var.www.html.gla.mysite.templates.Layout.SectionHolder.ss on line 57

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: How to use <% control %> and <% if %> Link to this post

    you have the function in the class SectionHolder.php and you are trying to call it from a template SectionMenu.ss? Im guessing you are including SectionMenu.ss in SectionHolder.ss

  • Andy
    Avatar
    230 Posts

    Re: How to use <% control %> and <% if %> Link to this post

    <% control Children %> should work fine, I'm not sure what getChildrenOf() is supposed to do?

  • Tkop
    Avatar
    28 Posts

    Re: How to use <% control %> and <% if %> Link to this post

    Willr - Yes SectionMenu is an Include to SectionHolder.ss.

    Andy - <% control Children %> is what I wanted. I thought I tried
    that before and got errors so I tried to write getChildrenOf() to get
    the children of a particular page by its Title. I just tired using Children
    and got the results that I wanted Thanks

    But for future reference can you see why the getChildrenOf() did not
    work? Am I misunderstanding the use of "control" or the way the
    "DataObject::get" works.

    1467 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.