Answers.Body: <p>As of <a href="https://craftcms.com/changelog#build2750" rel="nofollow">Craft 2.5.2750</a>, you can leave off the <code>{% endpaginate %}</code> tag, then move your <code>{% paginate %}</code> tag up outside of the blocks in the <code>posts/index.twig</code> template, and your <code>pageInfo</code> variable should be available to the whole template, including the parent template that you're extending.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-02T10:49:47.550Z
Answers.Text: Thanks Mike! Clean and very simple, I took some code from templates pre december 2015. I could've saved me some time if I've read the docs before posting it here. It works like a charm now. Thanks again.
Answers.UserDisplayName: ctigelaar
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-02T10:40:26.710Z
Answers.LastActivityDate: 2016-02-02T10:40:26.710Z
Answers.UserDisplayName: Mike Pepper
Body: <p>I'm trying to get my head around the following issue. I have a site which uses a base layout template <code>base.twig</code>, on which 3 layout templates are build (using <code>extends</code>). One of them is <code>main.twig</code>.</p>
  
  <p>I want to use the paginate information variable <code>pageInfo</code> (<a href="https://craftcms.com/docs/templating/paginate#the-pageInfo-variable" rel="nofollow">see docs</a>) in a block that's defined in the base template, to show the total number of entries found in the <code>{% block pageTitle %}{% endblock %}</code>. I tried a number of things, including defining a <code>pageTitle</code> variable in the <code>base.twig</code> template, to override in the content block, but all without any luck.</p>
  
  <p>These are stripped down versions of my files:</p>
  
  <p><strong>_layouts/base.twig</strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;{{ title }}&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          {% block header %}{% endblock %}
          &lt;main&gt;
              {% block pageTitle %}{% endblock %}
              {% block main %}{% endblock %}
          &lt;/main&gt;
          {% block footer %}{% endblock %}
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>_layouts/main.twig</strong></p>
  
  <pre><code>{% extends "_layouts/base" %}
  
  {% block main %}
      &lt;div class="main"&gt;
          {% block content %}{% endblock %}
      &lt;/div&gt;
  {% endblock %}
  </code></pre>
  
  <p><strong>posts/index.twig</strong></p>
  
  <pre><code>{% extends "_layouts/main" %}
  {% set title = 'My posts listing' %}
  
  {% set entries = craft.entries... %}
  
  {% block content %}
      {% paginate entries as pageInfo, pageEntries %}
          &lt;section&gt;
              {% for entry in pageEntries %}
                  &lt;article&gt;
                      &lt;h2&gt;{{ entry.title }}
                  &lt;/article&gt;
              {% endfor %}
          &lt;/section&gt;
  
          {% block pageTitle %}
              &lt;h1&gt;{{ pageInfo.total }} entries found&lt;/h1&gt;
          {% endblock %}
  
      {% endpaginate %}
  {% endblock %}
  </code></pre>
  
  <p>I know this has to do with variable scopes, but how can I use the paginate information outside my <code>content</code> block? One solution I tried does indeed works, but do I really need to copy the <code>{% paginate %}</code> statement inside my <code>pageTitle</code> block to get this working? That seems to be very inefficient to me:</p>
  
  <p><strong>posts/index.twig</strong></p>
  
  <pre><code>{% extends "_layouts/main" %}
  {% set title = 'My posts listing' %}
  
  {% set entries = craft.entries... %}
  
  {% block content %}
      {% paginate entries as pageInfo, pageEntries %}
          &lt;section&gt;
              {% for entry in pageEntries %}
                  &lt;article&gt;
                      &lt;h2&gt;{{ entry.title }}&lt;/h2&gt;
                  &lt;/article&gt;
              {% endfor %}
          &lt;/section&gt;
      {% endpaginate %}
  {% endblock %}
  
  {% block pageTitle %}
      {% paginate entries as pageInfo, pageEntries %}
          &lt;h1&gt;{{ pageInfo.total }} entries found&lt;/h1&gt;
      {% endpaginate %}
  {% endblock %}
  </code></pre>
  
  <p>Hope you can help me out or point me in the right direction. Any tips regarding a better structure for the blocks are also welcome. Twig seems so popular, so you'd think it can't be that hard for such simple tasks? Maybe I'm using the whole block concept totally wrong in the first place.</p>
  
Tags: <templating><pagination>
Title: Use paginate info in another block
ThreadText: # Use paginate info in another block
  
  (Asked by: username_0 on 2016-02-02)
  
  I'm trying to get my head around the following issue. I have a site which uses a base layout template `base.twig`, on which 3 layout templates are build (using `extends`). One of them is `main.twig`.
  
  I want to use the paginate information variable `pageInfo` ([see docs](https://craftcms.com/docs/templating/paginate#the-pageInfo-variable)) in a block that's defined in the base template, to show the total number of entries found in the `{% block pageTitle %}{% endblock %}`. I tried a number of things, including defining a `pageTitle` variable in the `base.twig` template, to override in the content block, but all without any luck.
  
  These are stripped down versions of my files:
  
  **\_layouts/base.twig**
  
  ```
  <html>
      <head>
          <title>{{ title }}</title>
      </head>
      <body>
          {% block header %}{% endblock %}
          <main>
              {% block pageTitle %}{% endblock %}
              {% block main %}{% endblock %}
          </main>
          {% block footer %}{% endblock %}
      </body>
  </html>
  
  ```
  
  **\_layouts/main.twig**
  
  ```
  {% extends "_layouts/base" %}
  
  {% block main %}
      <div class="main">
          {% block content %}{% endblock %}
      </div>
  {% endblock %}
  
  ```
  
  **posts/index.twig**
  
  ```
  {% extends "_layouts/main" %}
  {% set title = 'My posts listing' %}
  
  {% set entries = craft.entries... %}
  
  {% block content %}
      {% paginate entries as pageInfo, pageEntries %}
          <section>
              {% for entry in pageEntries %}
                  <article>
                      <h2>{{ entry.title }}
                  </article>
              {% endfor %}
          </section>
  
          {% block pageTitle %}
              <h1>{{ pageInfo.total }} entries found</h1>
          {% endblock %}
  
      {% endpaginate %}
  {% endblock %}
  
  ```
  
  I know this has to do with variable scopes, but how can I use the paginate information outside my `content` block? One solution I tried does indeed works, but do I really need to copy the `{% paginate %}` statement inside my `pageTitle` block to get this working? That seems to be very inefficient to me:
  
  **posts/index.twig**
  
  ```
  {% extends "_layouts/main" %}
  {% set title = 'My posts listing' %}
  
  {% set entries = craft.entries... %}
  
  {% block content %}
      {% paginate entries as pageInfo, pageEntries %}
          <section>
              {% for entry in pageEntries %}
                  <article>
                      <h2>{{ entry.title }}</h2>
                  </article>
              {% endfor %}
          </section>
      {% endpaginate %}
  {% endblock %}
  
  {% block pageTitle %}
      {% paginate entries as pageInfo, pageEntries %}
          <h1>{{ pageInfo.total }} entries found</h1>
      {% endpaginate %}
  {% endblock %}
  
  ```
  
  Hope you can help me out or point me in the right direction. Any tips regarding a better structure for the blocks are also welcome. Twig seems so popular, so you'd think it can't be that hard for such simple tasks? Maybe I'm using the whole block concept totally wrong in the first place.
  
  **Tags:** templating, pagination
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-02-02. Score: 3 | Accepted answer
  
  As of [Craft 2.5.2750](https://craftcms.com/changelog#build2750), you can leave off the `{% endpaginate %}` tag, then move your `{% paginate %}` tag up outside of the blocks in the `posts/index.twig` template, and your `pageInfo` variable should be available to the whole template, including the parent template that you're extending.
  
  > **Comments:**
  > **username_0**: Thanks username_1! Clean and very simple, I took some code from templates pre december 2015. I could've saved me some time if I've read the docs before posting it here. It works like a charm now. Thanks again.  
  
  ---
  
  