Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Issue #64: Set $context->type in render
Browse files Browse the repository at this point in the history
  • Loading branch information
johanjanssens committed May 3, 2016
1 parent 5607b49 commit c185830
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions code/template/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ final public function render($source, array $data = array(), $type = null)
$context->source = $source;
$context->type = $type;

//If content is a path find the type by locating the file
if($this->getObject('filter.path')->validate($source))
{
$locator = $this->getObject('template.locator.factory')->createLocator($source);

if (!$file = $locator->locate($source)) {
throw new \InvalidArgumentException(sprintf('The template "%s" cannot be located.', $source));
}

$context->type = pathinfo($file, PATHINFO_EXTENSION);
}

if ($this->invokeCommand('before.render', $context) !== false)
{
//Render the template
Expand All @@ -103,18 +115,6 @@ protected function _actionRender(TemplateContext $context)
{
$source = parent::render($context->source, ObjectConfig::unbox($context->data));

//If content is a path find the type by locating the file
if($this->getObject('filter.path')->validate($source))
{
$locator = $this->getObject('template.locator.factory')->createLocator($source);

if (!$file = $locator->locate($source)) {
throw new \InvalidArgumentException(sprintf('The template "%s" cannot be located.', $source));
}

$context->type = pathinfo($file, PATHINFO_EXTENSION);
}

if($context->type)
{
$source = $this->getObject('template.engine.factory')
Expand Down

0 comments on commit c185830

Please sign in to comment.