Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.


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

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

Custom Controls - Totally lost


18 Posts   6152 Views


5 September 2008 at 8:53am Community Member, 19 Posts

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.


5 September 2008 at 4:14pm Forum Moderator, 5511 Posts

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 - . Most of these are defined on ContentController (which your Page_Controller should extend) or Controller or Object...


5 September 2008 at 6:25pm Community Member, 19 Posts

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.


5 September 2008 at 6:31pm Forum Moderator, 5511 Posts

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


5 September 2008 at 7:43pm Community Member, 19 Posts

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:

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

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.


5 September 2008 at 7:54pm Forum Moderator, 5511 Posts

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


5 September 2008 at 8:02pm Community Member, 19 Posts

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.


5 September 2008 at 8:20pm Forum Moderator, 5511 Posts

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