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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Different Renderer. Replace SSViewer with different template system


Go to End


3 Posts   1870 Views

Avatar
elendal

Community Member, 2 Posts

20 December 2010 at 3:50pm

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

Forum Moderator, 5523 Posts

20 December 2010 at 6:31pm

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

Community Member, 2 Posts

21 December 2010 at 4:28am

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