Jump to:

1835 Posts in 1139 Topics by 554 members

Blog Module

SilverStripe Forums » Blog Module » custom BlogTree.php etc...

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 837 Views
  • losqualo
    Avatar
    Community Member
    17 Posts

    custom BlogTree.php etc... Link to this post

    Hi,

    Blog 0.4.0 with SS 2.4

    I have the blog folder installed at the correct place and I have my theme and theme_blog located in the themes folder. I also have my 'site' folder at the same level as 'blog' and 'themes'.

    I'd like to make modifications to the php files that are located in blog/code.

    I've tried copying the blog/code folder to

    themes/theme_blog/code
    themes/theme/code
    site/code

    The files are not being picked up from any location except blog/code.

    I don't like having my modified versions of BlogTree.php, BlogHolder.php and so on, including some of the widgets (e.g. TagCloudWidget.php) being in the root blog folder because of the problems this will create at time of upgrading the blog. There must be a way of having local to the theme or site folder, but I've not found a solution that works... I could just be getting in a mess.

    Where should I place local versions of files currently in blog/code?

    Thanks in advance

    Rob

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: custom BlogTree.php etc... Link to this post

    You can't override code as simple as you do with themes. In PHP you can only have 1 name per class. If you want to make modifications to the blog you either need to subclass it or use decorators to hook into any extend() calls the module makes. If you're making extensive changes subclassing the blog classes you need would be the best way.

    http://doc.silverstripe.org/dataobjectdecorator

    Subclassing is as easy as making your own file say CustomBlogTree.php with

    <?php

    class CustomBlogTree extends BlogTree {

    }

    class CustomBlogTree_Controller extends BlogTree_Controller {

    }
    ?>

    And using CustomBlogTree pages in your CMS rather than BlogTree. You can even 'hide' the original BlogTree as an option in the create menu by using a static http://api.silverstripe.org/2.4/cms/SiteTree.html#var$hide_ancestor

  • losqualo
    Avatar
    Community Member
    17 Posts

    Re: custom BlogTree.php etc... Link to this post

    Hi,

    Thanks for the guidance... I should of realised, but grew up coding before OOP, which remains utterly foreign to me most of the time...

    You said:

    >Subclassing is as easy as making your own file say CustomBlogTree.php with
    >
    ><?php
    >
    >class CustomBlogTree extends BlogTree {
    <
    >}
    >
    >class CustomBlogTree_Controller extends BlogTree_Controller {
    >
    >}
    >?>

    Where would I put tat file... inside mysite/code is my immediate instinct, or does there need to be a blog folder created under mysite?

    Thanks again

    Rob

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: custom BlogTree.php etc... Link to this post

    Mysite/code is the correct location for it.

    837 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.