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.

Customising the CMS

Different Renderer. Replace SSViewer with different template system


Reply

3 Posts   1148 Views

Avatar
elendal

20 December 2010 at 3:50pm Community Member, 2 Posts

Hello, there are many existing PHP renderers (ex mustache https://github.com/bobthecow/mustache.php or smarty) and I already use one.

I'm trying to integrate silverstripe into my system, but the problem is SSViewer is hardcoded into silverstripe.

What is the best way to replace it?

I would prefer silverstripe developers to extract an interface from SSViewer so that we can create an adapter to another view renderer and safely substitute SSViewer. And also create a factory class that would select correct renderer for each template.

Avatar
Willr

20 December 2010 at 6:31pm Forum Moderator, 5511 Posts

There is an effort going on to replace SSViewer. I'm not sure if this will allow other engines to be plugged in but more details will be available once it's near release (https://groups.google.com/d/msg/silverstripe-dev/U-V9wHkr0pw/4VquyohkATAJ). I doubt an easy 'plug and play' system for templates is going to be possible as even with the new template engine things like data structures / orm based features are still very tightly coupled to framework and going to be quite hard to abstract.

Remember seeing someone hack smarty rendering into SS2.3 (try a search) but it wasn't a practical addition to the framework.

Avatar
elendal

21 December 2010 at 4:28am Community Member, 2 Posts

For now I managed to post-process output and modify it before it is sent to the browser.
Also for now I managed to get it mostly working with my output renderers by including generated string into SSViewer output.

One more question, is it possibile to include the output of the method call into SSViewer? i.e instead of $var to do $func()

class GemsPage_Controller extends Page_Controller {
   private function gemsFilter($rawOutput) {
// perform search and replace here
   }

   function handleRequest(SS_HTTPRequest $request) {
      $this->pushCurrent();

      $response = parent::handleRequest($request);
      $rawOutput = $response->getBody();
      $translationFilter = new TranslationFilter();
      $cssFileter = new CssFilter(true);
      $jsFilter = new JsFilter(true);
      $response->setBody($this->gemsFilter($rawOutput));

      $this->popCurrent();
      return $response;
   }

   public function handleAction($request) {
      $result = parent::handleAction($request);
      return $this->gemsFilter($result);
   }
}