Getting the page URL in a pages collection loop

1.5k Views Asked by At

Im trying to build a dynamic menu to create a list of pages per tag. Is working fine except I don't know how to get the page url populated:

<section class="see-also">
{{#each tags}}
    <p>In <span class="tag">{{tag}}</span>:</p>
    {{#each pages}}
        <li><a href="#">{{data.title}}</a>{{pages.url}}</li>
    {{/each}}
{{/each}}
</section>

Any suggestions?

1

There are 1 best solutions below

1
On BEST ANSWER

@luis-martins you should be able to use the relative helper with the destination from the current page being rendered and the destination from the current page in the tags.pages collection like this to generate a relative url:

<section class="see-also">
{{#each tags}}
    <p>In <span class="tag">{{tag}}</span>:</p>
    {{#each pages}}
        <li><a href="#">{{data.title}}</a>{{relative ../../page.dest dest}}</li>
    {{/each}}
{{/each}}
</section>

Notice that to the the destination of the current page being rendered, you have to use the parent syntax from handlebars: ../../page.dest. Also the dest property is on the current page item from the tags.pages collection.

Hope this helps.