Hi,
I'm a newbie to silverstripe and by no means a developer. I was playing around with the blog module and trying to add an image to my blog entries, much like I would add a title to a post on the blogentry page through the backend (admin section). Seeing that I'm no developer I trolled the various blog entries on the blog module trying to find a suitable solution for my conundrum; This is how far I got;
Firstly I created a php file called; BlogEntryDecorator under the ....blog\code directory. I placed the following code in the page;
<?php
class BlogEntryDecorator extends DataObjectDecorator {
public function extraStatics(){
return array(
'has_one' => array(
"TitleImage" => "Image"
)
);
}
public function updateCMSFields(FieldSet &$fields) {
$fields->addFieldToTab("Root.Content.Main", new ImageField("TitleImage", "Title image"), 'Content');
}
}
?>
After creating the php file I pasted the following snippet into the _config under the ....\mysite directory
Object::add_extension('BlogEntry', 'BlogEntryDecorator');
Great!So after I applied the two changes I was able upload a image through a Image Title field for a BlogEntry page through the admin section. Everything seemed to work well. Now, all it seems I had to do was to reference the image field in the template pages by inserting the $ImageTitle variable (and I think this is where I might have gone, due to my lack of programming experience). I added the referenced the $ImageTitle variable in the BlogEntry.ss page under the ...themes\simplestripe\templates\Layout directory in the following manner;
<h1>$Parent.Title</h1>
<article>
<p class="ImageTitle">$ImageTitle</p>
<hgroup class="BlogTitle">
However, after refreshing the page I was still not able to see the image or any kind of reference of the image on the page. This led me to believe that I did something wrong :) and I came to the following conclusion;
1. Either I'm referencing the $ImageTitle variable incorrectly or I reference in the variable in the wrong .ss page.
2. I should not have created a separate BlogEntryDecorator php for the field definition.
3. Neither of the above and I'm totally off the path and shouldn't even have tried in the first place.
Can someone help me figuring out where I've gone wrong?
Thanks in advance