Skip to content

Commit

Permalink
Solves issue with type conflicts. use defaultTemplate propery to spec…
Browse files Browse the repository at this point in the history
…ify template name.
  • Loading branch information
romaninsh committed Jan 3, 2017
1 parent 4d2f1c6 commit f0ae37d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Icon.php
Expand Up @@ -4,7 +4,7 @@

class Icon extends View
{
public $template = 'icon.html';
public $defaultTemplate = 'icon.html';

public $content = 'circle help';
}
23 changes: 17 additions & 6 deletions src/View.php
Expand Up @@ -67,13 +67,24 @@ class View implements jsExpressionable
protected $skin;

/**
* Path to template. If you don't specify full path
* by starting with '/' then will be prepended by
* default template path.
* Template object, that, for most Views will be rendered to
* produce HTML output. If you leave this object as "null" then
* a new Template will be generated during init() based on the
* value of $defaultTemplate.
*
* @var Template
*/
public $template = 'element.html';
public $template = null;

/**
* Specifies how to initialize $template.
*
* If you specify a string, then it will be considered a filename
* from which to load the $template.
*
* @var string
*/
public $defaultTemplate = 'element.html';

/**
* Set static contents of this view.
Expand Down Expand Up @@ -209,8 +220,8 @@ public function init()
$this->initDefaultApp();
}

if (is_string($this->template)) {
$this->template = $this->app->loadTemplate($this->template);
if (is_string($this->defaultTemplate) && is_null($this->template)) {
$this->template = $this->app->loadTemplate($this->defaultTemplate);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ButtonTest.php
Expand Up @@ -23,7 +23,7 @@ public function testButtonIcon()

public function testBasicInit()
{
$layout = new \atk4\ui\Layout\App(['template'=>'./demos/templates/layout2.html']);
$layout = new \atk4\ui\Layout\App(['defaultTemplate'=>'./demos/templates/layout2.html']);

$layout->add(new H2('Basic Button'));
$layout->add(new Button())->set('Click me');
Expand Down

0 comments on commit f0ae37d

Please sign in to comment.