Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Custom Controls - Totally lost

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

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

Page: 1 2 3
Go to End
Author Topic: 6011 Views
  • Jona
    Avatar
    Community Member
    19 Posts

    Re: Custom Controls - Totally lost Link to this post

    I have another question that might solve my original one... Where can I find the code that SS uses to built all of the existing $Control methods? If I can get some examples or modify them as I see fit, this whole thing may be resolved.

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Custom Controls - Totally lost Link to this post

    FYI You code must be in the mysite/code/ folder or the tutorial/code folder. The themes/yourtheme/ folder is for HTML and CSS not the php methods.

    Theres a list of methods you can call from templates here - http://doc.silverstripe.com/doku.php?id=built-in-page-controls#quick_reference . Most of these are defined on ContentController (which your Page_Controller should extend) or Controller or Object...

  • Jona
    Avatar
    Community Member
    19 Posts

    Re: Custom Controls - Totally lost Link to this post

    Willr, thank you. You've been most helpful. I was putting my Page.php file in themes/themeName/code/ instead of tutorial/code/. Putting the Page.php file in tutorial/code/ worked. It turns out the solution was as simple as I'd thought: my lack of understanding the structure of SS.

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Custom Controls - Totally lost Link to this post

    Hopefully we will make this clearer in the future as we revisit the tutorials

  • Jona
    Avatar
    Community Member
    19 Posts

    Re: Custom Controls - Totally lost Link to this post

    I do hope so. The structure is very specific, and it's not necessarily a bad thing unless you're unfamiliar with said structure, which is the case with newcomers such as myself.

    I have another question, if it's not too much to ask. How can I set a $ControlVariable to change based on the iteration of its parent Control? (Sorry if my terminology is wrong.) For example, if I have:

          <ul>
           <% control Menu(2) %>
             <li><a href="$Link" id="$lowercaseMenuTitle">$MenuTitle</a></li>
        <% end_control %>
          </ul>

    How can my custom lowercaseMenuTitle method reference the current menu item? It seems that my method outputs an empty string when I place it within the Menu(2) control, yet works fine outside of it. I have tried things like SiteTree::getField("MenuTitle") and DataObject::getField("MenuTitle") but to no avail.

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Custom Controls - Totally lost Link to this post

    lowercaseMenuTitle will point to the database field lowercaseMenuTitle() which is defined on Page or Sitetree. Do you have a lowercaseMenuTitle in your db array in Page.php.

    A neat thing you can do in SS is even tho $lowercaseMenuTitle points to the lowercaseMenuTitle field in the db it looks first to a lowercaseMenuTitle() method, that means on Page.php you can define a lowercaseMenuTitle() function which has

    function lowercaseMenuTitle() {
    return strtolower($this->MenuTitle);
    }

    Now I think that works if you put that in the page controller class in page.php

  • Jona
    Avatar
    Community Member
    19 Posts

    Re: Custom Controls - Totally lost Link to this post

    I do not have a lowercaseMenuTitle field in the database. The reason is because I don't see a need to store information when it's something so simple. If the information were unique or required excessive processing, then I would add it to the db, but that isn't the case in this situation.

    The code you described works when I use it outside of a control, but not inside a control. I am still, for some reason, getting an empty string inside of the Menu(2) control.

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Custom Controls - Totally lost Link to this post

    Ok well try define it as getlowerCaseTitle() and try it in the page class rather then controller

    6011 Views
Page: 1 2 3
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.