0

We are working on a Silverstripe project that uses the Elemental Module to layout content.

The project also uses the Blog Module with the blog being used for two sections of the website - the work portfolio & a standard blog.

The challenge is: we want different content behaviour for each blog/section:

  1. Portfolio - Element Blocks
  2. Blog - standard blog/page behaviour

What is the best way to achieve this?

Should we extend Blog & BlogPost to new objects Portfolio & PortfolioItem to separate out the two different behaviours?

Or can we just add the following to the Blog Object/Controller:

if ($this->BlogType == 'portfolio'){
  // enable Elemental
} else {
  // disable Elemental
}

And finally, how do we disable Elemental on specific Pages? It isn't obvious in the documentation.

BaronGrivet
  • 4,364
  • 5
  • 37
  • 52

1 Answers1

0

This was our solution - using the includeElemental method to disable/ enable Elemental on a case by case basis.

class BlogPostExtension extends DataExtension
{
  public function updateCMSFields(FieldList $fields){
    $fields->insertBefore(new 
       DropdownField("LayoutIndex", "Layout", ["Portfolio", "Blog"]), "Title");
  }

  public function includeElemental(){
    if ($this->owner->LayoutIndex == 0) {
      return true;
    } else if ($this->owner->LayoutIndex == 1) {
      return false;
    }
  }   
}
BaronGrivet
  • 4,364
  • 5
  • 37
  • 52