8000 Use of parent() is broken in a case of intermediate template in inheritance chain · Issue #694 · twigjs/twig.js · GitHub
[go: up one dir, main page]

Skip to content

Use of parent() is broken in a case of intermediate template in inheritance chain #694

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

Closed
FlyingDR opened this issue Dec 15, 2019 · 0 comments · Fixed by #698
Closed

Use of parent() is broken in a case of intermediate template in inheritance chain #694

FlyingDR opened this issue Dec 15, 2019 · 0 comments · Fixed by #698

Comments

@FlyingDR
Copy link

Twig.js v1.14.0 breaks use of parent() function in a case if templates inheritance chain includes template that does not have a block that is referenced by parent().

Here is simplified setup to reproduce issue:

package.json

{
  "name": "twig-block-issue",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "twig": "1.14.0"
  }
} 

index.js

"use strict";

const Twig = require('twig');

Twig.renderFile('./a.twig', {}, (err, html) => {
    console.log(html);
}); 

a.twig

{% extends 'b.twig' %}

{% block content %}
    {{ parent() }}
    <h2>This one came from inherited template</h2>
{% endblock %}

b.twig

{% extends 'c.twig' %} 

c.twig

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Test</title>
</head>
<body>
{% block content %}
    <h1>This one is from original template</h1>
{% endblock %}
</body>
</html> 

I've also published it as a Gist to simplify downloading.

Attempt to rendering this set of templates using twig.js v1.14.0 with node index.js produces following error:

Error parsing twig template ./a.twig:
TypeError: Cannot read property 'render' of undefined
    at Twig.ParseState.parent (node_modules\twig\twig.js:4609:101)
    at parseParams.then.params (node_modules\twig\twig.js:2672:56)
    at Twig.Thenable.resolvedThen [as then] (node_modules\twig\twig.js:7889:41)
    at Twig.ParseState.parse (node_modules\twig\twig.js:2669:22)
    at Twig.async.forEach (node_modules\twig\twig.js:3187:50)
    at next (node_modules\twig\twig.js:8120:24)
    at Object.Twig.async.forEach (node_modules\twig\twig.js:8131:16)
    at Twig.ParseState.Twig.async.potentiallyAsync (node_modules\twig\twig.js:3169:31)
    at Object.Twig.async.potentiallyAsync (node_modules\twig\twig.js:7834:48)
    at Twig.ParseState.Twig.expression.parse (node_modules\twig\twig.js:3168:27)

if version of twig.js is downgraded to 1.13.3 - no error is produced and template renders correctly.

Issue also vanishes in a case if a.twig directly extends c.twig without intermediate template or in a case if b.twig also contains {% block content %}

drzraf pushed a commit to drzraf/twig.js that referenced this issue Dec 16, 2019
When looking for a block recursively search for grandparents too.
Fix twigjs#694
drzraf pushed a commit to drzraf/twig.js that referenced this issue Dec 18, 2019
drzraf pushed a commit to drzraf/twig.js that referenced this issue Dec 22, 2019
commit 7a4ae6e
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Sun Dec 22 00:46:27 2019 -0300

    support for "do" tag

commit 7658a92
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Sun Dec 22 00:35:23 2019 -0300

    The raw filter return a new Markup(content) which may itself return content
     if content is the empty string. The resulting output is [Object] instead of the expected
     empty string.

commit ec635df
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Sat Dec 21 17:20:14 2019 -0300

    Avoid attribute() to fail on undefined object

commit 001f05c
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Sat Dec 21 15:43:01 2019 -0300

    Provides sourcemaps

commit 8c4d9c2
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Tue Dec 17 21:56:29 2019 -0300

    search for block within all ascendants instead of parent only.
    fix twigjs#694
    reroll twigjs#695
drzraf pushed a commit to drzraf/twig.js that referenced this issue Dec 22, 2019
commit ae6c641
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Sun Dec 22 00:35:23 2019 -0300

    The raw filter returns a new Markup(content) which may itself returns the content
     if the content is an empty string or undefined.
    The resulting output is [Object] instead of the (expected) empty string.

commit 7a4ae6e
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Sun Dec 22 00:46:27 2019 -0300

    support for "do" tag

commit ec635df
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Sat Dec 21 17:20:14 2019 -0300

    Avoid attribute() to fail on undefined object

commit 001f05c
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Sat Dec 21 15:43:01 2019 -0300

    Provides sourcemaps

commit 8c4d9c2
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Tue Dec 17 21:56:29 2019 -0300

    search for block within all ascendants instead of parent only.
    fix twigjs#694
    reroll twigjs#695
drzraf pushed a commit to drzraf/twig.js that referenced this issue Dec 22, 2019
commit 867f369
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Sun Dec 22 00:46:27 2019 -0300

    support for "do" tag

commit ae6c641
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Sun Dec 22 00:35:23 2019 -0300

    The raw filter returns a new Markup(content) which may itself returns the content
     if the content is an empty string or undefined.
    The resulting output is [Object] instead of the (expected) empty string.

commit ec635df
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Sat Dec 21 17:20:14 2019 -0300

    Avoid attribute() to fail on undefined object

commit 001f05c
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Sat Dec 21 15:43:01 2019 -0300

    Provides sourcemaps

commit 8c4d9c2
Author: Raphaël Droz <raphael.droz+floss@gmail.com>
Date:   Tue Dec 17 21:56:29 2019 -0300

    search for block within all ascendants instead of parent only.
    fix twigjs#694
    reroll twigjs#695
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant
0