latte icon indicating copy to clipboard operation
latte copied to clipboard

{$this->hasBlock('test')} yields different result than {hasBlock('test')}

Open Gappa opened this issue 1 year ago • 0 comments

Version: 3.0.13 earlier versions probably too - related issue: #345

Bug Description

{$this->hasBlock('test')} yields different result than {hasBlock('test')}.

Relevant code:

  • https://github.com/nette/latte/blob/462444d669809528b6f6ce191b616d747c9b4bfc/src/Latte/Essential/CoreExtension.php#L194
  • https://github.com/nette/latte/blob/462444d669809528b6f6ce191b616d747c9b4bfc/src/Latte/Runtime/Template.php#L379-L382

When using {$this->hasBlock()} the LayerTop array has many entries of Latte\Runtime\Block instances (key being the block's name), but it is empty when called using {hasBlock()}. In fact, the whole $this->blocks array only contains another empty arrays in this case.

Steps To Reproduce

default.latte (template of a presenter's action)

{block test}Test{/block}

@layout.latte (main layout)

{$this->hasBlock('test')} {* true *}
{hasBlock('test')} {* false *}

Also, this in @layout.latte doesn't work:

{block test}test{/block}
{dump $this->hasBlock('test')}
{dump hasBlock('test')}

Result:

image

Which is strange, because on fiddle it works:

  • https://fiddle.nette.org/latte/#9f34b533f2

I tried to make a failing example on fiddle.nette.org/latte, but I'm not able to simulate the relation between @layout.latte and a presenter/action template.

Expected Behavior

Both approaches have the same result.

Possible Solution

N/A

Gappa avatar Feb 07 '24 14:02 Gappa