latte icon indicating copy to clipboard operation
latte copied to clipboard

Cannot redeclare block when using condition in {embed}

Open dakur opened this issue 5 years ago • 3 comments

Version: 2.9.2, 2.10.0

Bug Description

Parser throws: Latte\CompileException: Cannot redeclare block 'someBlock' in ...

Steps To Reproduce

Run Latte with this code in a template file:

{define aaa}
 <span>{block someBlock}{/block}</span>
{/define}

{embed aaa}
	{if 3 === 4}
		{block someBlock}a{/block}
	{else}
		{block someBlock}b{/block}
	{/if}
{/embed}

Expected Behavior

Output <span>b</span>

Note that I can't wrap {if} with {block} as I define multiple blocks so it would lead to repeating conditional logic in every block.

dakur avatar Jan 25 '21 15:01 dakur

This way the blocks do not work, see the documentation https://latte.nette.org/cs/template-inheritance#toc-layoutova-dedicnost:~:text=bez%20ohledu%20na%20to

dg avatar Jan 25 '21 15:01 dg

@dg Why is this actually? Is it just "not implemented" or is it conceptually impossible – something like want to run TS code directly in browser?

dakur avatar Jan 26 '21 08:01 dakur

It is conceptually impossible. It is something like

class Foo
{
	if (3 === 4) {
		function someBlock()
		{ return 'a' }
	} else {
		function someBlock()
		{ return 'b' }
	}
}

dg avatar Jan 26 '21 13:01 dg