I created a new page type that needs to break something down. I 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 manage dynamic data with this content.
I have in Straplines.php
following:
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 add the cms fields to HomePage.php. I can add straplines without problems, and they all appear. Then in HomePage.ss I have the following
<% include PricesBlock %> <% include TourStraplineBlock %> <% include QuickFacts %> <% include TourStraplineBlock %>
But then I can not figure out TourStraplineBlock to get separate content for each of them. Of course, there should be no parameters to parameterize include or not to create several templates. I am completely new to Silverstripe dev and find it difficult to create reusable content.
Edit: This is the strapline.ss template that handles the display.
<div class="strapline"> <% loop Straplines %> $Content <% end_loop%> </div>
As you probably can guess, if I put this twice, it will just show all the straplines. I want to do something like
<% include Strapline?id=1 %>
Then we decode it in Strapline.ss and go from there.
Sorry, yes, its 3.2 is not 3.0. I suggested that they are very similar.