@param $template
@param $fields

@return array
181714
public static function preparePropertyFields($template, $fields)
    {
        $templates = [];

        foreach ($fields as $field) {
            $fieldName = $field['name'];
            $type = $field['type'];
            $format = $field['format'];
            $propertyTemplate = str_replace('$FIELD_NAME$', $fieldName, $template);
            $description = $field['description'];
            if (empty($description)) {
                $description = $fieldName;
            }
            $propertyTemplate = str_replace('$DESCRIPTION$', $description, $propertyTemplate);
            $propertyTemplate = str_replace('$FIELD_TYPE$', $type, $propertyTemplate);
            if (!empty($format)) {
                $format = ",\n *          format=\"".$format.'"';
            }
            $propertyTemplate = str_replace('$FIELD_FORMAT$', $format, $propertyTemplate);
            $templates[] = $propertyTemplate;
        }

        return $templates;
    }
1186721
protected static function fetchTemplate( $template, $parameters = array() )
    {
        $tpl = eZTemplate::factory();
        $existingPramas = array();

        foreach( $parameters as $name => $value )
        {
            if ( $tpl->hasVariable( $name ) )
                $existingPramas[$name] = $tpl->variable( $name );

            $tpl->setVariable( $name, $value );
        }

        $result = $tpl->fetch( $template );

        foreach( $parameters as $name => $value )
        {
            if ( isset( $existingPramas[$name] ) )
                $tpl->setVariable( $name, $existingPramas[$name] );
            else
                $tpl->unsetVariable( $name );
        }

        return $result;
    }
1228307
public function getTemplateFile($template)
	{
	    if (!is_file($template)) {
	        $template = $this->getTemplatePath() . $this->_getRelativeTemplate($template) . $this->getSuffix();
	    }
	    
	    return $template;
	}
941196
public static function getTemplate($template, $format = 'html5')
	{
		$templates = static::getTemplates($template, $format = 'html5');

		return isset($templates[0]) ? $templates[0] : null;
	}
1167426
protected static function transform_template_brief(template $template) {
        global $OUTPUT;
        $exporter = new \core_competency\external\template_exporter($template);
        $data = $exporter->export($OUTPUT);
        return [
            'name' => $data->shortname,
            'description' => $data->description
        ];
    }
678833
private function scanFor($template)
    {
        $in = $this->dirs;
        $found = false;
        while (! $found && ! empty($in)) {
            $dir = array_shift($in);
            $found = $this->exists($dir, $template);
        }

        return $found;
    }
707573
protected function removeFromTemplate($template, $field) {
		$t = $this->getTemplate($template);
		$f = $this->getField($field);
		$success = $t->fieldgroup->remove($f);
		$t->fieldgroup->save();
		return $success;
	}
650917
protected function getFieldValues($fields)
    {
        $result = array();
        foreach ($fields as $id => $field) {
            if (isset($field['value'])) {
                $result[$id] = $field['value'];
            }
            if (!empty($field['fields'])) {
                /** @noinspection SlowArrayOperationsInLoopInspection */
                $result = array_merge($result, $this->getFieldValues($field['fields']));
            }
        }
        return $result;
    }
1205242
public function getChildTemplates(string $context): array
    {
        Splash::log()->Deb('Loading Standalone Connector Templates for '.$context);
        $result = array();
        //====================================================================//
        // Safety Check
        if (!in_array($context, array('New', 'Offline', 'Connected'), true)) {
            return $result;
        }
        //====================================================================//
        // Load templates for All Objects
        foreach ($this->getAvailableObjects() as $objectType) {
            $objectService = $this->getObjectService($objectType);
            if (method_exists($objectService, 'get'.$context.'Template')) {
                $result[] = $objectService->{'get'.$context.'Template'}();
            }
        }
        //====================================================================//
        // Return Results
        return $result;
    }
555254
protected function getParamArrayFor($template)
    {
        // get the style-params from the parent (if you like)
        $newVars = parent::getParamArrayFor($template);

        // If you configured two SwiftMailers, one with spooling and one without, then
        // all templates that have set the "SEND_IMMEDIATELY_FLAG = true" will be sent with the
        // mailer that does not use spooling => faster email delivery => e.g. for the Reset-Password-Email.
        if (self::VIP_INFO_MAIL_TEMPLATE == $template) {
            $newVars[self::SEND_IMMEDIATELY_FLAG] = true;
        }

        // add template specific stuff
        if (self::NOTIFICATIONS_TEMPLATE == $template) {
            $newVars['%someUrl%'] = 'http://example.com'; 				//$this->router->generate("your_route", $routeParamArray, UrlGeneratorInterface::ABSOLUTE_URL);
            $newVars['%someOtherUrl%'] = 'http://example.com/other';	//$this->router->generate("your_route", $routeParamArray, UrlGeneratorInterface::ABSOLUTE_URL);
        }

        // override some generic stuff needed for all templates
        $newVars['h2Style'] = "style='padding:0; margin:0; font:bold 24px Arial; color:red; text-decoration:none;'";

        // add an image that should be embedded into the html-email.
        $newVars['someRandomImage'] = $this->getTemplateImageDir().'someRandomImage.png';
        // after the image has been added here, it will be base64-encoded so it can be embedded into a html-snippet
        // see self::getSnippetArrayFor()

        return $newVars;
    }
866516
protected function fields(array $fields)
    {
        $result = array();
        foreach ($fields as $id => $field) {
            if (!isset($field['id'])) {
                $field['id'] = $id;
            }
            if (!isset($field['name'])) {
                $field['name'] = $id;
            }
            $result[$id] = $this->field($field);
        }
        return $result;
    }
1171284
protected function getPathToTemplates($template = null)
    {
        $template = Helpers::getPathWithSlash($template ?: Config::getDefaultTemplateName());
        $basePath = base_path(Config::getTemplatesPath() . $template);
        $path = Helpers::getPathWithSlash($basePath);

        if (!$this->isFileExists($path)) {
            throw new Exception('Invalid template. Make sure the following path exists: "' . $path . '"');
        }

        return $path;
    }
1060283
public function getIndexHeaderCells(array $fields = null)
    {
        $stub = $this->getStubContent('index.header.cell.blade', $this->template);
        $fields = $this->getFieldsToDisplay($fields);
        $rows = '';

        foreach ($fields as $field) {
            if ($field->isOnIndexView) {
                $row = $stub;
                $this->replaceFieldTitle($row, $this->getTitle($field->getLabel(), true))
                    ->replaceCommonTemplates($row, $field);
                $rows .= $row . PHP_EOL;
            }
        }

        return $rows;
    }
59430
protected function separateRows($templates)
    {
        $rows = [];
        foreach ($templates as $template) {
            $rows[] = $template;
            $rows[] = new TableSeparator();
        }
        unset($rows[count($rows) - 1]);

        return $rows;
    }
324836
protected function buildAllFields(array $fields) : array
    {
        foreach ($fields as $key => $field) {
            if ($field instanceof FieldBuilderBase) {
                $fields[$key] = $field->build();
            }
        }

        return $fields;
    }
885826
public function getPossibleViewFilesFromTemplates($templates)
    {
        return call_user_func_array('array_merge', array_map(function ($template) {
            return array_map(function ($extension) use ($template) {
                return str_replace('.', '/', $template).'.'.$extension;
            }, $this->extensions);
        }, $templates));
    }
1313107
public static function update_template($template) {

        $params = self::validate_parameters(self::update_template_parameters(), array('template' => $template));
        $params = $params['template'];
        $template = api::read_template($params['id']);
        self::validate_context($template->get_context());

        $params = (object) $params;

        return api::update_template($params);
    }