Jump to:

10990 Posts in 2727 Topics by 1818 members

All other Modules

SilverStripe Forums » All other Modules » Subsites - hack to filter page types by site

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1116 Views
  • Quarx
    Community Member
    12 Posts

    Subsites - hack to filter page types by site Link to this post

    I had to add a simple filtering by site type id (without this it will be a mess with 2 or 3 websites on one ss). It's not perfect but maybe someone will find it useful or will polish it further... This is how I did it.

    1. subsites/javascript/LeftAndMain_Subsite.js

    Modify onchange with the following code:

    onchange: function() {
             if($('Form_AddPageOptionsForm_SubsiteID')) {
                $('Form_AddPageOptionsForm_SubsiteID').value = this.value;
             var subsiteID = this.value;
                 url: SiteTreeHandlers.controller_url + '/changesubsite?SubsiteID=' + this.value + '&ajax=1',
                 success: function(sitetree_res) {
                          url: SiteTreeHandlers.controller_url + '/AddPageOptionsForm&subsiteID='+subsiteID+'&ajax=1',
                          success: function(responseText) {
                               // Modify form with ajax response (we take only options, the reset remains unchanged)
                               var cur = jQuery('#Form_AddPageOptionsForm').attr('id','Form_AddPageOptionsForm_Temp');
                               var cur_inner = jQuery('#Form_AddPageOptionsForm_PageType').attr('id','Form_AddPageOptionsForm_PageType_Temp');
                               var mod = jQuery('<div style="display:none">'+responseText+'</div>').insertAfter("#Form_AddPageOptionsForm_Temp");
                               var mod_inner = jQuery("#Form_AddPageOptionsForm_PageType").html();                                                      
                               // Fix for CMSMainLeft
                               addpageclass.prototype.originalValues.length = 0;                           
                               jQuery("#Form_AddPageOptionsForm_PageType option").each(function(){   
                                     'value': jQuery(this).val(),
                                     'label': jQuery(this).html()
                               if ($('sitetree')) {
                                  $('sitetree').innerHTML = sitetree_res;

    2. cms/code/CMSMain.php

    Modify AddPageOptionsForm() with the following code at the end:

          $out = new Form($this, "AddPageOptionsForm", $fields, $actions);
          if(Director::is_ajax() || $_GET["ajaxDebug"])

    3. sapphire/core/SiteTree.php

    In page_type_classes() at the following code:

             $current_subsite_id = Session::get('SubsiteID');
             $parent_subsite_id = $instance->stat('parent_subsite_id');
             if(isset($current_subsite_id) && isset($parent_subsite_id) && $parent_subsite_id != $current_subsite_id) {
                $kill_ancestors[] = $class;   


             if($ancestor_to_hide = $instance->stat('hide_ancestor')) {
                // note for killing later
                $kill_ancestors[] = $ancestor_to_hide;

    4. In all Pages where you want to limit page visibility to just one subsite add the following code to your class:

    public static $parent_subsite_id = YOUR_SUBSITE_ID; //your main site has "0" id

    Without parent_subsite_id your page will be visible for all subsites

    I tested this hack on SS2.4rc1 and it worked for: Create Page, Behavior tab and even with allowed_children set up.
    It's not perfect solution but I had to make it quickly since we I need to add a few subsites very soon and I have to move on to other tasks.

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.