Get the children from a specific page and add them to the main menu
<% with Page("about-us") %>
<% loop Children %>
$MenuTitle.XML
<% end_loop %>
<% end_with %>
Displaying news items on the homepage or in a sidebar
public function LatestNews($num = 5) {
// Get the new article holder
$holder = ArticleHolder::get()->First();
// Get the latest 5 news article
return ($holder) ? ArticlePage::get()->filter('ParentID', $holder->ID)->sort('Date DESC')->limit($num) : false;
}
The above mentioned code would usually go in the controller of the page type. It'll return an array that can then be access in template with <% loop LatestNews %>
The controller for a page is only created when page is actually visited, while the data object is available when the page is referenced in other pages, e.g. by page controls. A good rule of thumb is to put all functions specific to the page currently being viewed in the controller; only if a function needs to be used in another page should you put it in the data object.
- http://doc.silverstripe.org/framework/en/topics/datamodel
- http://doc.silverstripe.org/framework/en/tutorials/2-extending-a-basic-site
Whenever you want a chunk of code to run as soon as a controller class is initialized.
public function init() {
// Code here ...
// Call the parent method we're overriding and run that too so the chain of execution continues
parent::init();
}
Typically you'd overwrite the __constuct() method provided by default with PHP but SilverStripe uses a the custom method init() instead.
- Add an
uploadField()field to the CMS - Try to upload a file using the newly added field
- You may get error:
SyntaxError: Unexpected token E
Set write permission (potentially 777 depending on setup) to assets/Uploads
Add a page type description to increase user friendliness
static $description = 'This is a descriptive text about this page type';
Normal PHP arrays cannot be displayed in SS templates. You need to wrap them with ArrayData.
$list = Array(1 => "Cool", 2 => "Cooler");
return ArrayData($list);
Similiar to Google Chrome Developer Tools, the jQuery.entwine inspector allows you to see what entwine methods are bound to a specific element.
CTRL+` // CTRL + Backtick
Just what I needed to know, thank you :)