Defines a template for the given media type.

@param string $type The media type
@param string|callable $template The template
2366
public function setTemplate($type, $template)
    {
        if (!is_callable($template)) {
            $template = (string) $template;
        }

        $this->templates[$type] = $template;
    }
651709
public function template_include( $template ) {

		if ( '.twig' === substr( $template, - 5 ) ) {
			/** @var \Twig_Environment $twig */
			$twig = $this['twig.environment'];

			echo $twig->render( basename( $template ), apply_filters( 'meadow_context', array() ) );

			die();
		}

		return $template;
	}
775228
protected function addTemplateAssets($template)
    {
        /** @var SplFileInfo $file_info */
        foreach ($template->getAssets() as $filename => $file_info) {
            $this->assets->set($filename, $file_info->getRelativePathname());
        }
    }
355022
public function setTemplate($template)
    {
        if (!$this->id) {
            $this->getContentRoute()->setClassType(get_class($this));
            $this->getContentRoute()->setLocale($this->getLocale());
        }
        $this->getContentRoute()->setTemplate($template);

        return $this;
    }
677752
public function set_template($template)
	{
		// make sure the template is a View
		if (is_string($template))
		{
			$this->template = $this->view($template);
		}
		else
		{
			$this->template = $template;
		}

		// return the template view for chaining
		return $this->template;
	}
804090
protected function useTemplate($template, $status = 200, $minetype = 'html') {
		// Set the HTTP header status
		$this->response()->setStatusCode($status);

		// Set the minetype
		$this->response()->headers->set('Content-Type', $this->request()->getMimeType($minetype));

		// Set the template file
		$this->response()->template = $template;
	}
858204
protected function editInTemplateContext ($template, $field, callable $callback)
	{
		$template = $this->getTemplate($template);
		$fieldgroup = $template->fieldgroup;
		$field = $this->getField($field);

		$context = $fieldgroup->getField($field->name, true);
		$callback($context, $template);
		$this->fields->saveFieldgroupContext($context, $fieldgroup);
	}
1272045
public static function start_compile($template)
    {
        $key = self::get_key($template);
        self::$template_data[$key]['start_time'] = microtime(true);
    }
397520
public static function load($template)
	{
		// alter template so that it works
		$template = get_template_directory() != substr($template, 0, strlen(get_template_directory())) ? $template : substr($template, strlen(get_template_directory()) + 1);
		$template = get_stylesheet_directory() != substr($template, 0, strlen(get_stylesheet_directory())) ? $template : substr($template, strlen(get_stylesheet_directory()) + 1);
		$template = '.php' != substr($template, -4) ? $template : substr($template, 0, -4);
		// $template = 'templates.' == substr($template, 0, 10) ? $template : 'templates.' . $template;

		$mappedTemplate = static::mapTemplate($template);
		$template = locate_template($mappedTemplate);

		return new Loader($template);
	}
1175952
public function setTemplate(Template $template = null)
	{
		if ($this->writeOnce($this->template, $template)) {
			$this->template->addTemplateLayout($this);
		}
	}
553909
public function onLoadComponentTemplate(Template $template, $fileName)
	{
		if (!$this->activeTheme) {
			return;
		}

		$path = $this->activeTheme->getPath() . 'templates' . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . $fileName;
		if (file_exists($path)) {
			$template->setFile($path);
		} elseif ($parent = $this->activeTheme->getParent()) {
			$parentTheme = $this->getTheme($parent);
			$path = $parentTheme->getPath() . 'templates' . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . $fileName;
			if (file_exists($path)) {
				$template->setFile($path);
			}
		}
	}
560558
protected function renderTemplate($template, array $context = [])
    {
        $app = $this->getContainer();

        if ($this->pathAdded === false) {
            $this->addTwigPath('templates');
            $this->pathAdded = true;
        }

        return $app['twig']->render($template, $context);
    }
1158642
public function hydrate($template, $parameter)
    {
        if ($template->type == GroupParameterType::EDITABLE_HASHTABLE) {
            $parameter->setTemplate($template);
            if ($parameter->hasChildren()) {
                foreach ($parameter->getChildren() as $child) {
                    $this->hydrateRecursively($template, $child);
                }
            }
        } else {
            $this->hydrateRecursively($template, $parameter);
        }
    }
1178549
public static function add(HalcyonModel $template, $type = null)
    {
        if (!App::hasDatabase()) {
            return;
        }

        if (!LogSetting::get('log_theme')) {
            return;
        }

        if (!$type) {
            $type = self::TYPE_UPDATE;
        }

        $isDelete = $type === self::TYPE_DELETE;
        $dirName = $template->getObjectTypeDirName();
        $templateName = $template->fileName;
        $oldTemplateName = $template->getOriginal('fileName');
        $newContent = $template->toCompiled();
        $oldContent = $template->getOriginal('content');

        if ($newContent === $oldContent && $templateName === $oldTemplateName && !$isDelete) {
            traceLog($newContent, $oldContent);
            traceLog('Content not dirty for: '. $template->getObjectTypeDirName().'/'.$template->fileName);
            return;
        }

        $record = new self;
        $record->type = $type;
        $record->theme = Theme::getEditThemeCode();
        $record->template = $isDelete ? '' : $dirName.'/'.$templateName;
        $record->old_template = $oldTemplateName ? $dirName.'/'.$oldTemplateName : '';
        $record->content = $isDelete ? '' : $newContent;
        $record->old_content = $oldContent;

        if ($user = BackendAuth::getUser()) {
            $record->user_id = $user->id;
        }

        try {
            $record->save();
        }
        catch (Exception $ex) {}

        return $record;
    }
599843
public static function start_render($template)
    {
        $key = self::get_key($template);
        self::$template_data[$key]['start_time'] = microtime(true);
    }
589477
public function createFromTemplate($template)
    {
        $parameter = new GroupParameter();
        $parameter->setName($template->name);
        $parameter->setTemplate($template);
        if ($template->type == GroupParameterType::HASHTABLE && isset($template->entries)) {
            $parameter->setChildren($this->createRequiredFromTemplates($template->entries));
        } elseif ($template->type != GroupParameterType::HASHTABLE && $template->type != GroupParameterType::EDITABLE_HASHTABLE) {
            if ($template->type == GroupParameterType::BOOLEAN) {
                $value = true;
            } else {
                $value = empty($template->values) ? '' : $template->values[0];
            }
            $parameter->addValue($value);
        }
        return $parameter;
    }
328330
public function execute(\Template $template)
	{
		if(!Bootstrap::isEnabled())
		{
			return;
		}

		foreach($GLOBALS['BOOTSTRAP']['templates']['modifiers'] as $config)
		{
			if($config['disabled'] || !$this->isTemplateAffected($template->getName(), $config['templates']))
			{
				continue;
			}

			if($config['type'] == 'replace')
			{
				if(is_callable($config['replace']))
				{
					$value = call_user_func($config['replace'], $template);
				}
				else
				{
					$value = $config['replace'];
				}

				$template->$config['key'] = str_replace($config['search'], $value, $template->$config['key']);
			}
			elseif($config['type'] == 'callback')
			{
				call_user_func($config['callback'], $template);
			}
		}
	}