Modul ClassExtension should deliver a new template-file aswell

Hi I ve written a module that extends, let’s say, the PageController::class. To use the new functionality of my ExtendPage::class I need to overwrite the standard Page.ss with a new one delivered with my module that extends PageController…
How to do that :wink:

thanks in advance
fabi

Hi

SS4 is all about the namespace, so if you need to create ss template files for the classes that you create, you need to follow the trails.

For example, this is your subclass (of PageController)

<?php

namespace App\Web\Layout;
use PageController;
...

class MyPageController extends PageController {}

Then, the template you are looking for is
PROJECT_ROOT/themes/THEME_NAME/templates/App/Web/Layout/Layout/MyPageController.ss


or, you can override renderWith() function in your class to add more flexibilities (e.g. if x happens, I would like to use y.ss instead)

Hope this helps

Chees
Leo

hej, thank for youre reply
it does not work in my situation I guess.
If I would extend the i.e. PageController in that way, my class needs to be extended aswell, isn’t it?
MyPageController will only be taken if the class is ‘MyPage’. If so, the user has to change all the pagetypes in the CMS…
I would like to extend the PageController via a DataExtension so the classname does not have to be changed.

renderWith() sounds great but I have no idea how to use it,… which function do I have to overload/decorate to get renderWith take controll of the rendering?

You can use it like:
$this->renderWith([THE_STRING_OF_THE_TEMPLATENAME, 'Page']);

so it doesn’t have to be the same name as the page class name

Sure, but where to call it. In the doc you only find an example for an additional ajax-call

https://docs.silverstripe.org/en/4/developer_guides/templates/rendering_templates/

this is not working(ProductTest is reachable):

class OrderSale_ProductControllerExtension extends DataExtension{
	private static $allowed_actions = ["ProductTest"];
	public function ProductTest(){
		return "ProductTest";
	}
	protected function init(){
		//parent::init(); //with or without...
		$this->renderWith(['OrderSale_Product', 'Page']);
	}
}

I found onAfterInit as a hook for the ini(). It gets called but it does still not render with my alternative template-file

public function onAfterInit(){
	$this->getOwner()->renderWith(['OrderSale_Product', 'Page']);
}