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

include TwigException #49

Open
AnneCav opened this issue Jan 14, 2018 · 7 comments
Open

include TwigException #49

AnneCav opened this issue Jan 14, 2018 · 7 comments

Comments

@AnneCav
Copy link

AnneCav commented Jan 14, 2018

First of all, thank you for your plugin, I use it a lot :)

I've tryed to update from 0.5.0 to the latest version but when I run the task (which worked fine with 0.5.0) it returns a lot of twigexception like this one:

Error parsing twig template dev/templates/_layout/base.twig: 
TwigException: Unable to find template file dev/templates/_inc/styleguide/3-breadcrumb.twig

Task:

gulp.task('twig',"compile twig", function() {
  return gulp.src('./dev/pages/**/*.twig')
    .pipe(twig({
      base: './dev/templates/',
      data: {baseURL, config, configPackage, configScampi},
      extend: twigMarkdown
    }))
    .pipe(gulp.dest('./public/pages/'));
});

Nevertheless, templates are compiled.

Did I miss something?

@AnneCav
Copy link
Author

AnneCav commented Jan 15, 2018

So, after many tests, it appears that the problem is due to hyphens in the file name. Is it possible to fix this in the plugin?

@jameelmoses
Copy link

Experiencing the same issue with a nested include, where I'm including a partial in a partial. It compiles, but I get an exception that it's unable to find the template file. My file also has hyphens in the filename.

@olets
Copy link
Collaborator

olets commented Jun 28, 2018

Oops look like this ticket slipped through the cracks.

@jameelmoses for you is there no error if the file name doesn't have hyphens?

@jameelmoses
Copy link

I can check in the morning and report back

@jameelmoses
Copy link

So it looks like this issue for me is actually related to kss-node not being able to locate the nested include and not an issue with gulp-twig

@paulgoodfield
Copy link

@jameelmoses Did you manage to get nested includes working? When it tries to compile the following twig code I get the error TwigException: include function does not exist and is not defined in the context. I'm trying to pass an include as data to the card.twig component.

{% include 'components/card.twig' with {
    title: "My Title",
    actions: [
        include('components/button', {
            text: "Click Me"
        }, false)
    ]
} only %}

@jameelmoses
Copy link

yes, my issue was with kss-node and needing to use relative paths for nested includes. i've never attempted an implementation the way you're doing so can't really speak to it, but i will says when I am passing variable includes into a template, the best way is to use embed and have a block inside of it.

example:

{# components/card.twig #}
<div class="card">
  <div class="card-title">{{ title }}</div>
  {% block extra_stuff %}{% endblock %}
</div>

{# components/button.twig #}
<button>{{ text }}</button>

{# page.twig #}
{% embed 'components/card.twig' with { title: 'My Title' } %}
  {% block extra_stuff %}
    {% include 'components/button.twig' with { text: 'Click Me' } %}
  {% endblock %}
{% endembed  %}

alternatively, if you always just have an optional button, you should just be able to do this also:

{# components/card.twig #}
<div class="card">
  <div class="card-title">{{ title }}</div>
  {% if button_text %}
    {% include 'components/button.twig' with { text: button_text } %}
  {% endif %}
</div>

{# components/button.twig #}
<button>{{ text }}</button>

{# page.twig #}
{% include 'components/card.twig' with { title: 'My Title', button_text: 'Click Me' } %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants