simon-dt / gulp-twig

Twig plugin for gulp.js, The streaming build system. Looking for maintainer or collaborators. See wiki
https://github.com/zimmen/gulp-twig/wiki/Looking-for-maintainer-or-collaborator(s)
MIT License
62 stars 33 forks source link

Embed before "block page" empties "block page" #22

Closed kluplau closed 6 years ago

kluplau commented 8 years ago

Hi

Thank you for an awesome plugin.

I have this issue, where when I embed a .twig-file, the "block page" returns empty. When I delete the embed the "block page" returns the page content.

Layout

    <section class="content">
        {% embed "../modules/menu/menu.twig" %}{% endembed %}

        {% block page %}{% endblock %}
    </section>

Index.twig

    {# index.twig #}
    {% extends "../layouts/layout.twig" %}

    {% set title = "Forside" %}

    {% block page %}
      content
    {% endblock %}

Menu.twig

<nav role="navigation">
    <ul>
        {% for main in menu.main %}
            <li>
                <a href="{{ main.link }}">
                    {{main.title}}
                </a>

                {% if main.sub %}
                    <ul>
                        {% for sub in main.sub %}
                            <li>
                                <a href="{{ sub.link }}">
                                    {{ sub.title }}
                                </a>
                            </li>
                        {% endfor %}
                    </ul>
                {% endif %}
            </li>
        {% endfor %}
    </ul>
</nav>
kluplau commented 8 years ago

@zimmen Can you help me with this one?

simon-dt commented 8 years ago

What happens when you remove the embed (or use include instead of embed)

rlahoda commented 8 years ago

I used the original poster's code and had the same issue. I switched {% embed "sidebar.twig" %}{% endembed %}

to

{% include "sidebar.twig" %}

and it worked correctly for me.

fredfigo commented 7 years ago

I had a similar issue.

Code structure that happens the problem below:

{% block stylesheets %}
  {{ parent() }}
  <link href="{{ paths.css }}pages/account.css" rel="stylesheet">
{% endblock %}

{% block content %}
  <div class="container">

  {% embed 'layouts/l-grid-3-9.twig' %}

    {% block sidebar_content %}
      sidebar content
    {% endblock %}

    {% block body_content %}
      body content
    {% endblock %}

  {% endembed %}

  </div>
{% endblock %}

{% block javascripts %}
  {{ parent() }}
  {% include 'block/account/b-javascripts.twig' %}
{% endblock %}

What happens?

The content after the parent() function in stylesheets block returns empty. It works when placing the stylesheets block after content block.

I decided to do a test putting the stylesheet block after the content block when I realized that the javascripts block was not returning empty.

I switched for:

{% block content %}
  <div class="container">

  {% embed 'layouts/l-grid-3-9.twig' %}

    {% block sidebar_content %}
      sidebar content
    {% endblock %}

    {% block body_content %}
      body content
    {% endblock %}

  {% endembed %}

  </div>
{% endblock %}

{% block stylesheets %}
  {{ parent() }}
  <link href="{{ paths.css }}pages/account.css" rel="stylesheet">
{% endblock %}

{% block javascripts %}
  {{ parent() }}
  {% include 'block/account/b-javascripts.twig' %}
{% endblock %}
olets commented 7 years ago

@Blueblau this sounds like a twig.js issue. Are you still having the problem? twig.js has some open "embed" issues - those might be useful, or you might be able to add to them