Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Blog Module /

Discuss the Blog Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

show BlogHolder content on HomePage


Go to End


2 Posts   2313 Views

Avatar
shellsuper

Community Member, 1 Post

3 June 2014 at 7:28pm

Hi there,

I just learn a bit about SS 3.1 and blog module. I have 2 questions at the moment:
1. I am developing some kind of online learning website which provides several courses (e.g. math, chemistry, etc). Therefore, I made each course to have its own blog module. At this moment I want to add one image as a banner for each course and it is embedded in blogHolder. I added the code on the blog/code/BolgHolder.php like this:

class BlogHolder extends BlogTree implements PermissionProvider {
.....
static $has_one = array(
'Owner' => 'Member',
'Photo' => 'Image',
);

.....
function getCMSFields() {
$blogOwners = $this->blogOwners();

SiteTree::disableCMSFieldsExtensions();
$fields = parent::getCMSFields();
SiteTree::enableCMSFieldsExtensions();

//sets the ID and Name Map for Blog Ownership
$owners = new DropdownField('OwnerID', 'Blog owner', $blogOwners->map('ID', 'Name')->toArray());
$owners->setEmptyString('(None)');
$owners->setHasEmptyDefault(true);

$fields->addFieldToTab('Root.Main', new CheckboxField('TrackBacksEnabled', 'Enable TrackBacks'), "Content");
$fields->addFieldToTab('Root.Main', $owners, "Content");
$fields->addFieldToTab('Root.Main', new CheckboxField('AllowCustomAuthors', 'Allow non-admins to have a custom author field'), "Content");
$fields->addFieldToTab("Root.Main", new CheckboxField("ShowFullEntry", "Show Full Entry"), "Content");
$fields->addFieldToTab("Root.Images", new UploadField('Photo'));

$this->extend('updateCMSFields', $fields);

return $fields;
}
.....

Although it works like the way I want it, is it the right way to do it? I hacked in into the code instead of creating a new Holder page.

2. How do I get the content & image from the BlogHolder (not the BlogEntry) so it can be shown on the HomePage?

Thank you

Avatar
helenclarko

Community Member, 166 Posts

13 November 2014 at 12:55pm

I might be able to answer your second question, but first you should look into Datmodels and how to pull data from your SQL database.

http://doc.silverstripe.org/framework/en/topics/datamodel

Then you could do something like:

HomePage.php

	function BlogHolder(){
		return $Blog = BlogHolder::get()->limit(5);	
	}

Then insipe your HomePage.ss file

you will need to add a loop for BlogHolder:

<% loop BlogHolder %>
and within the loop you should be able to pull data from the BlogHolder table in your SQL database