Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template inheritance has strange block override priority? #317

Closed
xelsas opened this issue Nov 17, 2016 · 1 comment
Closed

Template inheritance has strange block override priority? #317

xelsas opened this issue Nov 17, 2016 · 1 comment

Comments

@xelsas
Copy link

xelsas commented Nov 17, 2016

When overriding a block with sub block in a parent two templates up, and a template in between only overrides the sub blocks, the code in the sub blocks in the parent template seems to override the blocks in the highest template. This and can generate a fatal error as shown in the following example. I am aware that this is quite an obscure example, and not 100% sure if this is working as intended or not.

edits: some typos and better wording of the behavior I'm seeing

PHP code:

<?php

require_once __DIR__ . '/lib/Smarty3/libs/Smarty.class.php';

class Test
{
	public function test()
	{
		return "test!";
	}

}

$smarty = new Smarty();

$tpl = $smarty->createTemplate(__DIR__ . '/test_smarty.tpl');

$tpl->assign('test_object', new Test());

$tpl->display();

test_smarty.tpl

{extends file="test_smarty_parent.tpl"}

{block name="block1"}
	{block name="block1.1"}block1.1<br />{/block}
	{block name="block1.2"}block1.2<br />{/block}
{/block}

test_smarty_parent.tpl

{extends file="test_smarty_parent_2.tpl"}

{block name="block1.1"}parent block1.1<br />{/block}
{block name="block1.2"}
	parent block1.2
	{$test->test()}
	<br />
{/block}
{block name="block1.3"}parent block1.3<br />{/block}

test_smarty_parent_2.tpl

<html>
<head></head>
<body>
	{block name="block1"}
		{assign var="test" value=$test_object}
		{block name="block1.1"}parent 2 block1.1<br />{/block}
		{block name="block1.2"}parent 2 block1.2<br />{/block}
		{block name="block1.3"}parent 2 block1.3<br />{/block}
	{/block}
</body>
</html>

This generates the following output:

parent block1.1
parent block1.2 
( ! ) Fatal error: Call to a member function test() on a non-object in <hash>.file.test_smarty_parent.tpl.php on line 59
...
@xelsas xelsas changed the title Code that is not displayed is still executed Code in blocks that are not displayed is still executed Nov 17, 2016
@xelsas xelsas changed the title Code in blocks that are not displayed is still executed Template inheritance has strange block override priority? Nov 17, 2016
uwetews added a commit that referenced this issue Nov 19, 2016
…block} could call sub-bock content from parent

    template #317
@uwetews
Copy link
Contributor

uwetews commented Nov 19, 2016

This bug is now fixed in the master branch

@uwetews uwetews closed this as completed Nov 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants