/** * Render this form using the given template, and return the result as a string * You can pass either an SSViewer or a template name * @param string|array $template * @return DBHTMLText */ public function renderWithoutActionButton($template) { $custom = $this->customise(array("Actions" => "")); if (is_string($template)) { $template = new SSViewer($template); } return $template->process($custom); }
/** * Execute the given template, passing it the given data. * Used by the <% include %> template tag to process templates. * * @param string $template Template name * @param mixed $data Data context * @param array $arguments Additional arguments * @param Object $scope * @return string Evaluated result */ public static function execute_template($template, $data, $arguments = null, $scope = null) { $v = new SSViewer($template); $v->includeRequirements(false); return $v->process($data, $arguments, $scope); }
/** * Render this object into the template, and get the result as a string. You can pass one of the following as the * $template parameter: * - a template name (e.g. Page) * - an array of possible template names - the first valid one will be used * - an SSViewer instance * * @param string|array|SSViewer $template the template to render into * @param array $customFields fields to customise() the object with before rendering * @return DBHTMLText */ public function renderWith($template, $customFields = null) { if (!is_object($template)) { $template = new SSViewer($template); } $data = $this->customisedObject ? $this->customisedObject : $this; if ($customFields instanceof ViewableData) { $data = $data->customise($customFields); } if ($template instanceof SSViewer) { return $template->process($data, is_array($customFields) ? $customFields : null); } throw new UnexpectedValueException("ViewableData::renderWith(): unexpected " . get_class($template) . " object, expected an SSViewer instance"); }
/** * Renders a panel containing tools which apply to the currently displayed edit form. * The main difference to {@link Tools()} is that the panel is displayed within * the element structure of the form panel (rendered through {@link EditForm}). * This means the panel will be loaded alongside new forms, and refreshed upon save, * which can mean a performance hit, depending on how complex your panel logic gets. * Any form fields contained in the returned markup will also be submitted with the main form, * which might be desired depending on the implementation details. * * @return String HTML */ public function EditFormTools() { $templates = $this->getTemplatesWithSuffix('_EditFormTools'); if ($templates) { $viewer = new SSViewer($templates); return $viewer->process($this); } else { return false; } }
public function testRequireCallInTemplateInclude() { //TODO undo skip test on the event that templates ever obtain the ability to reference MODULE_DIR (or something to that effect) if (FRAMEWORK_DIR === 'framework') { $template = new SSViewer(array('SSViewerTestProcess')); Requirements::set_suffix_requirements(false); $this->assertEquals(1, substr_count($template->process(array()), "tests/javascript/forms/RequirementsTest_a.js")); } else { $this->markTestSkipped('Requirement will always fail if the framework dir is not ' . 'named \'framework\', since templates require hard coded paths'); } }
/** * Render server configuration file from a template file * * @param string $template * @return string Rendered results */ protected function renderTemplate($template) { // Build allowed extensions $allowedExtensions = new ArrayList(); foreach (File::config()->allowed_extensions as $extension) { if ($extension) { $allowedExtensions->push(new ArrayData(array('Extension' => preg_quote($extension)))); } } $viewer = new SSViewer(array($template)); return (string) $viewer->process(new ArrayData(array('AllowedExtensions' => $allowedExtensions))); }
/** * Load all the template variables into the internal variables, including * the template into body. Called before send() or debugSend() * $isPlain=true will cause the template to be ignored, otherwise the GenericEmail template will be used * and it won't be plain email :) * * @param bool $isPlain * @return $this */ protected function parseVariables($isPlain = false) { $origState = SSViewer::config()->get('source_file_comments'); SSViewer::config()->update('source_file_comments', false); if (!$this->parseVariables_done) { $this->parseVariables_done = true; // Parse $ variables in the base parameters $this->templateData(); // Process a .SS template file $fullBody = $this->body; if ($this->ss_template && !$isPlain) { // Requery data so that updated versions of To, From, Subject, etc are included $data = $this->templateData(); $candidateTemplates = [$this->ss_template, ['type' => 'email', $this->ss_template]]; $template = new SSViewer($candidateTemplates); if ($template->exists()) { $fullBody = $template->process($data); } } // Rewrite relative URLs $this->body = HTTP::absoluteURLs($fullBody); } SSViewer::config()->update('source_file_comments', $origState); return $this; }