Closed notakoder closed 2 years ago
That's not the previous, but parent page. You can use Pico's pages
Twig function (see https://picocms.org/in-depth/features/pages-function/):
At some other place you might have heard that Pico’s
pages()
function also accepts theoffset
parameter. […] There’s only one common use case: Accessing a page’s parent page. Remember the example above: You’reshop
and you want to learn more about your parent. Just passoffset=-1
(i.e.pages("shop", offset=-1)
), it will returnindex
. Keep in mind that thepages()
function returns pages only, sopages("shop/flowers/daisies", offset=-1)
will return nothing, because there’s noshop/flowers/index.md
page.
Try this:
{% set parent_page = pages(current_page.id, offset=-1)|first %}
Yes, parent page it is. Sorry about mislabelling it. :)
I did try using pages()
function with offset
value of -1
and it almost worked. The url of the links correctly links to the respective parent page. However, a /Array
string attached to the end of each url, thus resulting in 404 error. Not sure why. I use folder.md
naming convention instead of folder/index.md
. To verify that the error is not due to that, I created an index.md
file within a folder only to see the same error. Here is my code.
{% set parent_page = pages(current_page.id, offset=-1)|first %}
<a href="{{ parent_page }}">Back</a>
By the way, the in-depth page is written well. I think there must be a index page for in-depth articles. :)
parent_page
holds the parent page's data. You'll have to use Pico's link
Twig filter, the same you'd use it elsewhere.
{% set parent_page = pages(current_page.id, offset=-1)|first %}
<a href="{{ parent_page.id|link }}">Back</a>
By the way, the in-depth page is written well. I think there must be a index page for in-depth articles. :)
Yes. Even though there are way more issues about our docs :see_no_evil:
Thank worked. Thanks. On re-reading the doc,
pages("shop") returns the data of page shop/shipping.md
Subtle things you miss. :)
Yes. Even though there are way more issues about our docs see_no_evil
I'll try to make some time for improving them. :)
Thanks for the help by the way.
I have a directory structure as follows and I am trying to set up a link on each page to the previous index page. ie, a link on
file5.md
andfile6.md
pointing totopic.md
and a link onfile1.md
,file2.md
,file3.md
andtopic.md
pointing toblog.md
.I am currently using conditional statements in the main template for to insert the links, like:
This is a tiresome process as I have to insert it for every directory inside
content
and every sub directory insideblog
. Is there a better way (like a twig variable) to go to previous directory's index page that I can apply to all?