nette / latte

☕ Latte: the safest & truly intuitive templates for PHP. Engine for those who want the most secure PHP sites.
https://latte.nette.org
Other
1.09k stars 107 forks source link

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

Closed Gappa closed 4 months ago

Gappa commented 5 months ago

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

Bug Description

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

Relevant code:

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:

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 commented 4 months ago

Thanks, it is working now 👍


Note for anyone updating - if you see this error, don't panic 🙂

The solution is easy - clear latte cache.

TypeError
Latte\Essential\CoreExtension::Latte\Essential\{closure}(): Argument #1 ($template) must be of type Latte\Runtime\Template, string given, called in /{path_to_project}/temp/cache/latte/Front-templates-@layout.latte--c33d85f130.php on line 321

image