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.
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
- Previous 10 entries
- 1
- Page 22(current)
- 3
- Next 10 entries
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...
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.
Hopefully we will make this clearer in the future as we revisit the tutorials
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.
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
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.
Ok well try define it as getlowerCaseTitle() and try it in the page class rather then controller
- Previous 10 entries
- 1
- Page 22(current)
- 3
- Next 10 entries