I have created a new page type that needs something to break up the content. I have created a strapline block that i would like to use in 3 places on the page, however i want to create only 1 version of the strapline block and drive that content by dynamic data.
I have the following in Straplines.php
class Straplines extends DataObject{
private static $db = array(
'Title'=>'Text',
'Content'=>'HTMLText',
'SortOrder'=>'Int'
);
private static $has_one = array(
'Parent'=>'Page'
);
private static $default_sort = 'SortOrder';
public function getCMSFields(){
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Main", new HtmlEditorField('Content','Content'));
$fields->addFieldToTab("Root.Main", new TextField('Title','Title'));
return $fields;
}
}
Then i add the cms fields to HomePage.php. I can add straplines no problem there and they all show up. Then in HomePage.ss i have the following
<% include PricesBlock %>
<% include TourStraplineBlock %>
<% include QuickFacts %>
<% include TourStraplineBlock %>
But then I cannot figure out away in TourStraplineBlock to get separate content for each of these. Surely there must be away to parameterize the include or not have to create multiple templates. I'm quite new to Silverstripe dev and am finding it a tough process to create re-usable content.
Edit: This is the strapline.ss template that handles displaying.
<div class="strapline">
<% loop Straplines %>
$Content
<% end_loop%>
</div>
As you can probably guess, if i put this in twice it simply shows all the straplines. I want to do something like
<% include Strapline?id=1 %>
Then decode that in Strapline.ss and go from there.
Edit sorry yes its 3.2 not 3.0. I assumed that they were quite similar.
private static $db
sounds definitly NOT like Silverstripe 3.0, more like 3.1 or 3.2. What Version of SS are you using? And could you show more code of HomePage.php and the include template you want to modify? – Roswell