Skip to content
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

PL does not support twig extends #554

Closed
gael-boyenval opened this issue Nov 7, 2016 · 15 comments
Closed

PL does not support twig extends #554

gael-boyenval opened this issue Nov 7, 2016 · 15 comments
Labels
help wanted 🆘 pinned 📌 Don't let stalebot clean this up

Comments

@gael-boyenval
Copy link
Contributor

gael-boyenval commented Nov 7, 2016

I am using Pattern Lab Node v2.6.1 on Mac, with Node v6.7, using the Gulp Edition.

Expected Behavior

when extending a template, it extend the template…
it is referenced here too : #285

Actual Behavior

when extending, pl make it like including

Steps to Reproduce

x.twig

foo
{% block content %}
    bar
{% endblock %}

=> output foobar

y.twig

{% extends "x.twig" %}
foo
{% block content %}
    baz
{% endblock %}

=> output foobar to
=> should output foobaz

z.twig

{% extends "x.twig" %}
foo
{% block content %}
    {{ parent() }}
    baz
{% endblock %}

=> output foobarbar
=> should output foobarbaz

@max-dombrowski
Copy link

max-dombrowski commented Mar 29, 2017

I have the same issue. Any progress on this? For me it looks like extends acts like include.

@bmuenzenmeyer
Copy link
Member

Unfortunately, I doubt it/

Our initial contributor to the Twig engine has not been seen in a while

Cross - linking to #285

@KatieMFritz
Copy link

Has anyone found a workaround for this? Maybe with Nunjucks? I wish I could fix it but my JS and PHP chops aren't there yet. 😕

@gael-boyenval
Copy link
Contributor Author

gael-boyenval commented May 17, 2017

@KatieMFritz @bmuenzenmeyer.

I looked into it quickly.
It could be possible to use the twig engine but the current problem is that it is not possible to use inline templates when including/extending twig templates in one another.

So we have to use templates file path in order to render them.

@bmuenzenmeyer : finally it only require for the object param passed to the renderPattern method to give us the root template path (the user's _pattern directory). It is currently not the case.
If you can do that I could update the twig pattern-engine in order to make it work.

@KatieMFritz
Copy link

@gael-boyenval, thanks for the quick response!

I played around with Nunjucks for a while last night, but I keep getting an error with it so I'm stuck. I'll report back if I get it working.

@bmuenzenmeyer
Copy link
Member

@gael-boyenval thanks for the sluething and the direction - I can see what I can do :)

@bmuenzenmeyer bmuenzenmeyer self-assigned this May 17, 2017
@gael-boyenval
Copy link
Contributor Author

@KatieMFritz : nunjucks is another template engine. If you want it to work you'll have to develop a pattern-engine, a pattern-lab specific component on top of nunjucks.

@bmuenzenmeyer
Copy link
Member

bmuenzenmeyer commented Sep 22, 2017

I spent too long trying to get this to work tonight. No combination of the below seemed to work:

  renderPattern: function renderPattern(pattern, data) {
    var result = twig({
      allowInlineIncludes: true,
      path: path.relative(__dirname, path.resolve(process.cwd(), 'source', '_patterns', pattern.relPath)
      //data: pattern.template
    }).render(data);
    return result;
  },

cannot call render() on undefined.
disregarding the hard-codes, I may try to swap to node-twig next

@bmuenzenmeyer bmuenzenmeyer added the hacktoberfest 🌾 https://hacktoberfest.digitalocean.com label Sep 28, 2017
bmuenzenmeyer added a commit to pattern-lab/patternengine-node-twig that referenced this issue Oct 1, 2017
@sghoweri
Copy link
Contributor

sghoweri commented Oct 1, 2017

@bmuenzenmeyer if you wanted to assign this one to me I can take a crack at this this week

bmuenzenmeyer referenced this issue in pattern-lab/patternengine-node-twig Oct 2, 2017
@bmuenzenmeyer
Copy link
Member

if you wanted to assign this one to me I can take a crack at this this week

gopher it!

@sghoweri
Copy link
Contributor

sghoweri commented Oct 8, 2017

@bmuenzenmeyer taking another look at this now!

@dnwhte
Copy link
Member

dnwhte commented Oct 9, 2017

I'm working on a Nunjucks engine that's nearly complete. I resolved this issue by...

  1. Setting expandPartials to false. FYI, this disables inline templates.

  2. Since inline templates are disabled the full pattern path must be supplied for nunjucks to work. With inspiration from the underscore engine, I created a partialRegistry array that keeps track of pattern.patternPartial and pattern.relPath in the registerPartial function.

  3. In renderPattern I iterate the partialRegistry and replace instances of patternPartial with the relPath in pattern.extendedTemplate.

May not be the best solution, but something that's working for now.

@bmuenzenmeyer bmuenzenmeyer removed the hacktoberfest 🌾 https://hacktoberfest.digitalocean.com label Nov 10, 2017
@stale
Copy link

stale bot commented Jan 9, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the needs response label Jan 9, 2018
@stale stale bot closed this as completed Jan 16, 2018
@bmuenzenmeyer bmuenzenmeyer added the pinned 📌 Don't let stalebot clean this up label Jan 16, 2018
@bmuenzenmeyer bmuenzenmeyer reopened this Jan 16, 2018
@stale
Copy link

stale bot commented Mar 17, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@ringods
Copy link
Contributor

ringods commented Apr 28, 2020

This is supported in package @pattern-lab/engine-twig since version 5.8.0

https://github.com/pattern-lab/patternlab-node/blob/dev/CHANGELOG.md#580-2020-04-03

@ringods ringods closed this as completed Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted 🆘 pinned 📌 Don't let stalebot clean this up
Projects
None yet
Development

No branches or pull requests

7 participants