21293 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 895 Views |
-
Layout function call problem

10 December 2009 at 12:46am
Hey,
I'm trying to call a function I made called DisplayCourse() which displays data from a data object but it's not working. The function is getting called in a layout file (Homepage.ss) but the function doesn't actually get called at all! It works in the main template file(Page.ss) but not in the layout.
Any help would be greatly appreciated.
Thanks!
-
Re: Layout function call problem

10 December 2009 at 1:48am
You really need to explain a bit more / post some code...
It probably has something to do with the method being in the wrong class .....
-
Re: Layout function call problem

10 December 2009 at 2:04am
Hey,
Thanks. I've posted the relevant code below. The code is just displaying the data from a data object called Course things like Date, title, location etc... on the front page. What's odd is that it's not even getting called when in the layout file.
Page.php
------------
class Page_Controller extends ContentController {...
public function DisplayCourse(){
die('function called'); //To test if function is getting called
$courses = DataObject::get("Course");
$results = ($courses) ? DataObject::get("Course", "", "", "", "") : false;
return ($results) ? $results : false;
}}
Layout/Homepage.ss
----------------------------...
<% control DisplayCourse %>
<div>
<p><strong>$Date.Nice</strong></p>
<p>$Location</p>
<p class="purple"><strong>$Title</strong></p>
<p class="purple">$Description</p>
› <a href="#" class="read-more">Read more</a>
</div>
<% end_control %>....
Course.php
--------------<?php
class Course extends DataObject
{
static $db = array (
'Date' => 'Date',
'Location' => 'Text',
'Title' => 'Text',
'Description' => 'Text'
);static $has_one = array (
'LearningAndDevelopmentPage1' => 'LearningAndDevelopmentPage1',
);public function getCMSFields_forPopup()
{
return new FieldSet(
new CalendarDateField('Date', 'Date of the course'),
new TextField('Location', 'Location of the course'),
new TextField('Title', 'Title of the course'),
new TextareaField('Description', 'Description of the course')
);
}
}?>
-
Re: Layout function call problem

10 December 2009 at 2:08am
Do you have a HomePage_Controller class as well ? If so , does it inherit from Page_Controller ?
-
Re: Layout function call problem

10 December 2009 at 2:37am
Should work then..
Is the <% control DisplayCourse %> in the top context ? (not within another control block) ?
-
Re: Layout function call problem

10 December 2009 at 2:47am
Ah ha, That was it! It was nested inside another control block.
Thanks Fuzz10!
| 895 Views | ||
|
Page:
1
|
Go to Top |


