Skip to content

Commit

Permalink
Honour templatePath set in Cell actions.
Browse files Browse the repository at this point in the history
When cells set their own templatePath we shouldn't muck about with that.

Refs #8271
  • Loading branch information
markstory committed Feb 17, 2016
1 parent 25665c2 commit 23bec50
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/View/Cell.php
Expand Up @@ -187,23 +187,25 @@ public function render($template = null)
));
}

$builder = $this->viewBuilder();

if ($template !== null &&
strpos($template, '/') === false &&
strpos($template, '.') === false
) {
$template = Inflector::underscore($template);
}
if ($template === null) {
$template = $this->viewBuilder()->template() ?: $this->template;
$template = $builder->template() ?: $this->template;
}

$builder = $this->viewBuilder();
$builder->layout(false);
$builder->template($template);
$builder->layout(false)
->template($template);

$className = substr(strrchr(get_class($this), "\\"), 1);
$name = substr($className, 0, -4);
$builder->templatePath('Cell' . DS . $name);
if (!$builder->templatePath()) {
$builder->templatePath('Cell' . DS . $name);
}

$this->View = $this->createView();
try {
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/View/CellTest.php
Expand Up @@ -142,6 +142,20 @@ public function testSettingCellTemplateFromAction()
$this->assertEquals('alternate_teaser_list', $appCell->viewBuilder()->template());
}

/**
* Tests that cell action setting the templatePath
*
* @return void
*/
public function testSettingCellTemplatePathFromAction()
{
$appCell = $this->View->cell('Articles::customTemplatePath');

$this->assertContains('Articles subdir custom_template_path template', "{$appCell}");
$this->assertEquals('custom_template_path', $appCell->template);
$this->assertEquals('Cell/Articles/Subdir', $appCell->viewBuilder()->templatePath());
}

/**
* Tests that cell action setting the template using the ViewBuilder renders the correct template
*
Expand Down
@@ -0,0 +1 @@
Articles subdir custom_template_path template
11 changes: 11 additions & 0 deletions tests/test_app/TestApp/View/Cell/ArticlesCell.php
Expand Up @@ -82,6 +82,17 @@ public function customTemplateViewBuilder()
$this->viewBuilder()->template('alternate_teaser_list');
}

/**
* Renders a template in a custom templatePath
* The template is set using the ViewBuilder bound to the Cell
*
* @return void
*/
public function customTemplatePath()
{
$this->viewBuilder()->templatePath('Cell/Articles/Subdir');
}

/**
* Simple echo.
*
Expand Down

0 comments on commit 23bec50

Please sign in to comment.