Jump to:

5539 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Different Renderer. Replace SSViewer with different template system

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

Page: 1
Go to End
Author Topic: 1130 Views
  • elendal
    Avatar
    Community Member
    2 Posts

    Different Renderer. Replace SSViewer with different template system Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Different Renderer. Replace SSViewer with different template system Link to this post

    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.

  • elendal
    Avatar
    Community Member
    2 Posts

    Re: Different Renderer. Replace SSViewer with different template system Link to this post

    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);
       }
    }

    1130 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.