pug-php / pug

Pug template engine for PHP
https://www.phug-lang.com
MIT License
391 stars 42 forks source link

Pug 2.7.6 minor correction to avoid warning with block append usage #251

Closed dadajuice closed 2 years ago

dadajuice commented 2 years ago

Hello,

I encountered a light issue when using append when used inside an inherited layout. The append behave as expected (it works) but it also throws in a warning. This only happens with at least two levels of "extends".

Example:

layout.pug

doctype html
html
  head
    title Test
  body
    h1 Header
    block content
    br
    br
    p Footer

layout2.pug

extends layout

block content
  p Testing

test.pug

extends layout2

append content
  p Working without warning.

Executing the test.pug rendering gets me the good result, but with the following warning (which does not appears if you have only one level of extends).

Warning: Undefined property: Jade\Nodes\Block::$mode in /var/www/html/vendor/pug-php/pug/src/Jade/Parser.php on line 426

I'm not sure why it happens with multiple inherited files only, but a simple fix would be to verify if the $mode property is set in the method affected by the warning to avoid it. I added the following lines in the method parseBlock() just after the $prev = &$this->blocks[$name]; line :

if (!isset($prev->mode)) {
    return $this->blocks[$name];
}

It fixed the problem in my local version. I was wondering if such a fix would be possible or if you had a better one 😊.

Thank you very much for your time!

dadajuice commented 2 years ago

Please note that there's another issue related to append if you use multiple append with the same context of multiple inherited files. The issue case was for one append block type ... if I would have another file extending with another append somehow the first element of the block doesn't appear (it keeps only the two append value). If you want I can open another issue for this specific case, but since it must be around the same code maybe there's a quick fix you may know of.

Thank you!

kylekatarnls commented 2 years ago

Hello, can you try if it's all good using composer require pug/pug-php:dev-version-2.next?

dadajuice commented 2 years ago

Seems all good! 😁 Thank you very much!

kylekatarnls commented 2 years ago

Tag released.