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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Blog Module /

Discuss the Blog Module.

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

Multiple Blog Templates


Go to End


5 Posts   392 Views

Avatar
SilverstripeLearner

Community Member, 15 Posts

24 February 2017 at 1:03am

I just installed Blog Module and set up my first blog called "News" and now I need to set up another blog called "Events". For the News blog I modified the layout straight into the blog files but now that I need a different layout for "Events" blog, I understand that I need another approach. I rad something about making an SuperBlogHolder and having BlogHolder just pass the $Layout but I didn't really understand how that works.

I would appreciate any response, thanks and have a great day !

Avatar
Michael J James

Community Member, 8 Posts

24 February 2017 at 10:19am

Edited: 24/02/2017 10:20am

Hi @SilverstripeLearner,

You can extend Blog to have a checkbox to switch the layout

<?php
class BlogExtension extends DataExtension {
    private static $db = array(
        'isEventHolder' => 'Boolean'
    );
    public function updateCMSFields(FieldList $fields) {
        $fields->addFieldToTab('Root.Main', CheckboxField::create('isEventHolder', 'Event Layout'),'Content');
    }
}

config.yml

Blog:
  extensions:
    - BlogExtension

Run a dev/build by visiting yourdomain.com/dev/build

Then have 2 Includes

BlogLayout.ss and EventLayout.ss

Then in the Blog template you can have an if statement

<% if isEventHolder == 1 %>
    <% include EventLayout %>
<% else %>
    <% include BlogLayout %>
<% end_if %>

Thanks
Michael

Avatar
SilverstripeLearner

Community Member, 15 Posts

28 February 2017 at 11:39am

Hello @Michael,

Thanks for your reply, I was short on time and what I've finally done to solve this is:
I created 2 templates: News and Events and both extend the Blog and it works fine. But now I have another problem, I want to display on my Homepage,
on the left side posts from News and on the right side posts from Events. I filtered the blog posts by their parent's ID but I hardcoded the ID. Any
idea how I dynamically get those ID's ?

Avatar
Michael J James

Community Member, 8 Posts

1 March 2017 at 2:22am

Edited: 01/03/2017 2:22am

Hi @SilverstripeLearner,

This will only work if you only have two blogs

Event

public function getEvents() {
    return Blog::get()->filter('isEventHolder' => '1')->first();
}

News

public function getNews() {
    return Blog::get()->filter('isEventHolder' => '0')->first();
}

Put both of these functions into your Page.php or Homepage.php

Then in your template you can do

Events

<% with getEvents %>
    <% loop Children.Sort('PublishDate','DESC').Limit(3) %>
        <a href="{$Link}">$Title</a>
    <% end_loop %>
<% end_with %>

News

<% with getEvents %>
    <% loop Children.Sort('PublishDate','DESC').Limit(3) %>
        <a href="{$Link}">$Title</a>
    <% end_loop %>
<% end_with %>

Thanks
Michael

Avatar
TGx`

Community Member, 10 Posts

24 June 2017 at 3:18pm

Edited: 24/06/2017 3:19pm

Thank you infomation.

สมัคร sbobet