/** * Renders the map info window for the DataObject. * * Be sure to define a template for that, named by the decorated class suffixed with _MapInfoWindow * e.g. MyPage_MapInfoWindow * * You can change the suffix globally by editing the MapExtension.map_info_window_suffix config val * * @return string */ public function getMappableMapContent() { $defaultTemplate = 'MapInfoWindow'; $classTemplate = SSViewer::get_templates_by_class($this->owner->ClassName, Config::inst()->get('MapExtension', 'map_info_window_suffix')); $template = count($classTemplate) ? $classTemplate : $defaultTemplate; return MapUtil::sanitize($this->owner->renderWith($template)); }
/** * action for showing a single news item */ public function show() { $templates = SSViewer::get_templates_by_class(__CLASS__, '_show'); $templates[] = 'Page'; //use this if you need e.g. different template for ajax $this->extend('updateTemplatesForShowAction', $templates); return $this->renderWith($templates); }
/** * Render this Page for $LayoutSection * @return \HTMLText */ public function LayoutSection() { $templates = SSViewer::get_templates_by_class(get_class($this), '', 'SiteTree'); foreach ($templates as &$template) { $template = "Section/{$template}"; } return $this->renderWith(new SSViewer($templates)); }
/** * Return a list of appropriate templates for this class, with the given suffix using * {@link SSViewer::get_templates_by_class()} * * @return array */ public function getTemplatesWithSuffix($suffix) { return SSViewer::get_templates_by_class(get_class($this), $suffix, 'LeftAndMain'); }
/** * @covers SSViewer::get_templates_by_class() */ public function testGetTemplatesByClass() { $self = $this; $this->useTestTheme('layouttest', function () use($self) { // Test passing a string $templates = SSViewer::get_templates_by_class('SSViewerTest_Controller', '', 'Controller'); $self->assertCount(2, $templates); // Test to ensure we're stopping at the base class. $templates = SSViewer::get_templates_by_class('SSViewerTest_Controller', '', 'SSViewerTest_Controller'); $self->assertCount(1, $templates); // Make sure we can filter our templates by suffix. $templates = SSViewer::get_templates_by_class('SSViewerTest', '_Controller'); $self->assertCount(1, $templates); // Test passing a valid object $templates = SSViewer::get_templates_by_class("SSViewerTest_Controller", '', 'Controller'); // Test that templates are returned in the correct order $self->assertEquals('SSViewerTest_Controller', array_shift($templates)); $self->assertEquals('Controller', array_shift($templates)); // Let's throw something random in there. $self->setExpectedException('InvalidArgumentException'); $templates = SSViewer::get_templates_by_class(array()); $this->assertCount(0, $templates); }); }
/** * Return an SSViewer object to render the template for the current page. * * @param $action string * * @return SSViewer */ public function getViewer($action) { // Manually set templates should be dealt with by Controller::getViewer() if (isset($this->templates[$action]) && $this->templates[$action] || isset($this->templates['index']) && $this->templates['index'] || $this->template) { return parent::getViewer($action); } // Prepare action for template search if ($action == "index") { $action = ""; } else { $action = '_' . $action; } $templates = array_merge(SSViewer::get_templates_by_class(get_class($this->dataRecord), $action, "SiteTree"), SSViewer::get_templates_by_class(get_class($this), $action, "Controller"), SSViewer::get_templates_by_class(get_class($this->dataRecord), "", "SiteTree"), SSViewer::get_templates_by_class(get_class($this), "", "Controller")); return new SSViewer($templates); }
/** * Return an SSViewer object to render the template for the current page. * * @param $action string * * @return SSViewer */ public function getViewer($action) { // Manually set templates should be dealt with by Controller::getViewer() if (isset($this->templates[$action]) && $this->templates[$action] || isset($this->templates['index']) && $this->templates['index'] || $this->template) { return parent::getViewer($action); } // Prepare action for template search if ($action == "index") { $action = ""; } else { $action = '_' . $action; } // Find templates by dataRecord $templates = SSViewer::get_templates_by_class(get_class($this->dataRecord), $action, "SiteTree"); // Next, we need to add templates for all controllers $templates += SSViewer::get_templates_by_class(get_class($this), $action, "Controller"); // Fail-over to the same for the "index" action $templates += SSViewer::get_templates_by_class(get_class($this->dataRecord), "", "SiteTree"); $templates += SSViewer::get_templates_by_class(get_class($this), "", "Controller"); return new SSViewer($templates); }
/** * @covers SSViewer::get_templates_by_class() */ public function testGetTemplatesByClass() { $self = $this; $this->useTestTheme(dirname(__FILE__), 'layouttest', function () use($self) { // Test passing a string $templates = SSViewer::get_templates_by_class('TestNamespace\\SSViewerTestModel_Controller', '', 'Controller'); $self->assertEquals(['TestNamespace\\SSViewerTestModel_Controller', 'Controller'], $templates); // Test to ensure we're stopping at the base class. $templates = SSViewer::get_templates_by_class('TestNamespace\\SSViewerTestModel_Controller', '', 'TestNamespace\\SSViewerTestModel_Controller'); $self->assertCount(1, $templates); // Make sure we can filter our templates by suffix. $templates = SSViewer::get_templates_by_class('TestNamespace\\SSViewerTestModel', '_Controller'); $self->assertCount(1, $templates); // Let's throw something random in there. $self->setExpectedException('InvalidArgumentException'); $templates = SSViewer::get_templates_by_class(array()); }); }
/** * renders the current page using the ClassName_onepage template, * e.g. Page_onepage * * The suffix is generated by @link getOnePageTemplateSuffix * * @return HTMLText */ public function getOnePageContent() { $templateName = SSViewer::get_templates_by_class($this->owner->Classname, $this->getOnePageTemplateSuffix(), 'SiteTree') ?: 'Page_onepage'; $controller = ModelAsController::controller_for($this->owner); return $controller->renderWith($templateName); }