<p>If I'm understanding you correctly, you want users when they visit your site to have a secondary menu that has links to various points in the article. That would actually be very easy to do in Craft. It's also possible for you to paginate a page, but that would be far more in-depth.</p>

<p>For skip links, you would need to run over the matrix twice. You will also need an anchor matrix block. It can either be a dedicated block for anchor tags, or a header block. You run over it the first time to create your menu:</p>

<pre><code>&lt;ul class="article menu"&gt;
{% for block in entry.articleMatrix.type('header') %}
    &lt;li&gt;&lt;a href="#{{ block.header|slugify }}"&gt;{{ block.header }}&lt;/a&gt;&lt;/li&gt;
{% endfor %}
&lt;/ul&gt;
</code></pre>

<p>Then later when you are running over your article, you can check for block type and add the id as needed:</p>

<pre><code>{% if block.type == "header" %}
    &lt;h1 id="{{ block.header|slugify }}"&gt;{{ block.header }}&lt;/h1&gt;
{% endif %}
</code></pre>

<p>This is a really basic example. It uses <a href="https://gist.github.com/boboldehampsink/7354431">Bob Olde Hampsink's slugify plugin</a> (it uses Craft's built in slug method). It would be better if you could determine (maybe with a drop down field in your block) what level of heading the block is. I suggest you also cache each matrix loop for performance.</p>

CC BY-SA 3.0
2014-06-25T21:20:44.667Z
Nice answer, Bryan! To further improve this, you could exchange the `replace` filter with Bob Olde Hampsink's [`slugify`](https://gist.github.com/boboldehampsink/7354431) filter, which uses Craft's core slug technology.
carlcs
CC BY-SA 3.0
2014-06-25T21:25:27.683Z
Good idea! It's been added.
Bryan Redeagle
CC BY-SA 3.0
2014-06-25T19:58:11.350Z
2014-06-25T21:24:45.617Z
2014-06-25T21:24:45.617Z
Bryan Redeagle
<p>If you just mean to create an anchor-link menu, just use this plugin: <a href="https://github.com/pixelandtonic/Anchors">Anchor</a></p>

<p>.</p>

<p>If you want to create a multi-site article pagination, you could do it like this:</p>

<ul>
<li>Add a page-break-block to your matrix.  </li>
<li><p>Get your entry by the slug's segment:</p>

<pre><code>{% set entry = craft.entries.section('section_handle').slug( craft.request.getSegment(2) ) %}
</code></pre></li>
<li><p>Add a route which redirects to the template, if an additional segment is added, for example:</p>

<blockquote>
  <p>something/{slug}/{*}</p>
</blockquote></li>
<li><p>You could check with a conditional in your template what lastSegment is passed, and depending on it, show parts of your matrix.</p></li>
</ul>

CC BY-SA 3.0
2014-06-25T19:42:17.267Z
I think he's referring to this being on the front-end. I think this because he mentioned a snippet in WordPress (a shortcode methinks).
Bryan Redeagle
CC BY-SA 3.0
2014-06-25T19:48:55.917Z
Ah ok, makes sense. I'll edit the answer.
Victor
CC BY-SA 3.0
2014-06-25T19:39:34.650Z
2014-06-25T20:12:12.867Z
2014-06-25T20:12:12.867Z
Victor
<p>I'm not sure I fully understand what you are trying to do, but I think this may apply as an option to consider.  Matrix Blocks are Element Types and the {% paginate %} tag works with all Element Types.</p>

<p>So you could treat your blocks as you would a section with entries, and paginate them.  A simple example:</p>

<pre><code>{% paginate entry.articleMatrix.limit(3) as blocks %}

  {% for block in blocks %}

    {# Display all your blocks output as needed #}
    &lt;div class="block {{ block.type }}"&gt;
      {% include "_partials/blocks/" ~ block.type %}   
    &lt;/div&gt;

    {% if paginate.prevUrl %}
    &lt;a href="{{ paginate.prevUrl }}"&gt;Previous Page&lt;/a&gt;
    {% endif %}

    {% if paginate.nextUrl %}
        &lt;a href="{{ paginate.nextUrl }}"&gt;Next Page&lt;/a&gt;
    {% endif %}

  {% endfor %}

{% endpaginate %}
</code></pre>

<p><a href="http://buildwithcraft.com/docs/templating/tags#paginate" rel="nofollow">Pagination in the Craft Docs</a></p>

CC BY-SA 3.0
2014-06-25T22:59:40.647Z
2014-06-25T22:59:40.647Z
Ben Parizek
<p>I'm writing some pretty huge articles consisting of multiple (80+) Matrix blocks of various types. They're so long they'd benefit from in-article navigation for skip-links.</p>

<p>WordPress has a plugin called autogen_menu which creates linked navigation from the header hierarchy in a post. You just put in a small snippet where you want the generated nav to go and it generates all the links (and presumably id's on the headers) itself. Has Craft got anything similar, I've not been able to find a plugin that does this?</p>

<p>Or, would this be better outside of Craft entirely and done as JS?</p>

CC BY-SA 3.0
2014-06-26T08:39:22.480Z
Thanks for the answers guys, but they're only doing half of what I mean, and the Matrix route would end up with me having some 140+ blocks on a single page - 80 is already causing slow-down in the UI.

Maybe an example is better:

See here: https://mattwilcox.net/archives/setting-up-a-secure-home-web-server-with-raspberry-pi/

The Menu and links at the top are being automatically generated from the article. That's what I would like.
Matt Wilcox
<navigation>
Automatic in-page navigation plugin?
# Automatic in-page navigation plugin?

(Asked by: username_0 on 2014-06-25)

I'm writing some pretty huge articles consisting of multiple (80+) Matrix blocks of various types. They're so long they'd benefit from in-article navigation for skip-links.

WordPress has a plugin called autogen\_menu which creates linked navigation from the header hierarchy in a post. You just put in a small snippet where you want the generated nav to go and it generates all the links (and presumably id's on the headers) itself. Has Craft got anything similar, I've not been able to find a plugin that does this?

Or, would this be better outside of Craft entirely and done as JS?

**Tags:** navigation

> **Comments:**
> **username_0**: Thanks for the answers guys, but they're only doing half of what I mean, and the Matrix route would end up with me having some 140+ blocks on a single page - 80 is already causing slow-down in the UI.  Maybe an example is better:  See here: https://mattwilcox.net/archives/setting-up-a-secure-home-web-server-with-raspberry-pi/  The Menu and links at the top are being automatically generated from the article. That's what I would like.  

---

## 3 answers

### Answer by username_1 on 2014-06-25. Score: 11

If I'm understanding you correctly, you want users when they visit your site to have a secondary menu that has links to various points in the article. That would actually be very easy to do in Craft. It's also possible for you to paginate a page, but that would be far more in-depth.
For skip links, you would need to run over the matrix twice. You will also need an anchor matrix block. It can either be a dedicated block for anchor tags, or a header block. You run over it the first time to create your menu:

{% for block in entry.articleMatrix.type('header') %}
    {{ block.header }}
{% endfor %}


Then later when you are running over your article, you can check for block type and add the id as needed:
{% if block.type == "header" %}
    {{ block.header }}
{% endif %}

This is a really basic example. It uses Bob Olde Hampsink's slugify plugin (it uses Craft's built in slug method). It would be better if you could determine (maybe with a drop down field in your block) what level of heading the block is. I suggest you also cache each matrix loop for performance.

> **Comments:**
> **username_2**: Nice answer, Bryan! To further improve this, you could exchange the `replace` filter with Bob Olde Hampsink's [`slugify`](https://gist.github.com/boboldehampsink/7354431) filter, which uses Craft's core slug technology.  
> **username_1**: Good idea! It's been added.  

---

### Answer by username_3 on 2014-06-25. Score: 5

If you just mean to create an anchor-link menu, just use this plugin: Anchor
.
If you want to create a multi-site article pagination, you could do it like this:

Add a page-break-block to your matrix.  
Get your entry by the slug's segment:
{% set entry = craft.entries.section('section_handle').slug( craft.request.getSegment(2) ) %}

Add a route which redirects to the template, if an additional segment is added, for example:

something/{slug}/{*}

You could check with a conditional in your template what lastSegment is passed, and depending on it, show parts of your matrix.

> **Comments:**
> **username_1**: I think he's referring to this being on the front-end. I think this because he mentioned a snippet in WordPress (a shortcode methinks).  
> **username_3**: Ah ok, makes sense. I'll edit the answer.  

---

### Answer by username_4 on 2014-06-25. Score: 2

I'm not sure I fully understand what you are trying to do, but I think this may apply as an option to consider.  Matrix Blocks are Element Types and the {% paginate %} tag works with all Element Types.
So you could treat your blocks as you would a section with entries, and paginate them.  A simple example:
{% paginate entry.articleMatrix.limit(3) as blocks %}

  {% for block in blocks %}

    {# Display all your blocks output as needed #}
    
      {% include "_partials/blocks/" ~ block.type %}   
    

    {% if paginate.prevUrl %}
    Previous Page
    {% endif %}

    {% if paginate.nextUrl %}
        Next Page
    {% endif %}

  {% endfor %}

{% endpaginate %}

Pagination in the Craft Docs


---

