Linking back to Draft Page that has ?Token=secret-link

Hi - having a little diffciulty getting my head around the page URL template code.

I have a page set up that is not published - it is a draft page that can be accessed by a “secret link”.
The page lists a bunch of items that have a detail page.
I want to put a link on each detail page that takes me back to the master draft page.
I think I am supposed to “find” the draft page in some way and then output its URL including the token, but I am not getting anywhere.

Forgive if this is really basic stuff, but not for me!

Many thanks for any help.

$page->parent()->url()

does not work?

Unfortunately not - that wants to take me back to the overall master list.
My set up is: A master list - then I assign certain items to a “private page” (in the panel as a catergory)
This works great.
So the private page only contains the items that have this category.
Not sure if that is the problem.

And this private page is a separate page in the file system? Can’t you get it by its id then

kirby()->page('path/to/private/page')->url()

Let me try that

So, yes this works, as ‘hard-coded’ way - what I was hoping for was a way to insert the ‘page ID’ or its URL into the code - from the panel - so that i could modify it per private page - (I have several)
e.g.
kirby()->page(‘URL-of-private-page-inserted-from-blueprint’)->url()

does that make any sense?

You mean, add it to every subpage in the Panel? Yes, that would be possible.

And if I wanted to add it only once - in the blueprint of the private page - what would the resulting template code be? This is the bit that is hard for me to figure out!

Maybe I’m missing something here, the structure is not clear to me. What is the relationship between the private page and the pages listed on each private page?

Here is my structure (and maybe this is where I am going all wrong - but it works up to a point).

My content folder contains a folder:

artworks

this contains a hundred individual artworks:

1_artwork_1
2_artwork_2
etc…

then I have several “private pages” (as draft pages) in addition to a master “work” (published) page: these are templates:

work.php
privateview1.php
privateview2.php
etc…

I have an artworkmaster.php snippet that each page uses (private or not) - (perhaps this is also where I am going wrong). This contains the following pagination for example:

    <?php 
$param = param('category');
$collection = $page->siblings()->listed()->filterBy('categories', $param, ','); ?>



<ul class="pagination">

  <?php if ($page->hasPrevListed($collection)) : ?>
    <li class="prevList" style="padding-right:10px">



      <a href="<?= $page->prevlisted($collection)->url(['params' => ['category' => $param]]); ?>">PREVIOUS </a>



    </li>
  <?php endif ?>

  <?php if ($page->hasNextListed($collection)) : ?>
    <li>
    |<a class="nextList" style="padding-left:10px" href="<?= $page->nextlisted($collection)->url(['params' => ['category' => $param]]); ?>">NEXT</a>
    </li>
  <?php endif ?>

</ul>

The templates retrieve which artworks I want (i have assigned the artwork a category on the panel) by using the following:

<?php foreach ($privatePages = $pages->children()->filterby('categories', 'privateview', ',') as $artwork): ?>

then each artwork links to a detail page using the following:

<a href=" <?= url($artwork->id(), ['params' => ['category' => 'privateview']]); ?>">

I am hoping to insert in the single artworkmaster.php snippet the code that links back to its relevant main page.

So the privateview to use (1 or 2 or maybe more) depends on the category? But is this a 1:1 relation, or can artwork x belong to multiple views both public and private?

Hi, yes, it can belong to multiple

In that case, the easiest option would be to use a query string in the URL that leads to the single page indicating the parent, and read that query string in the single page to return back to the previous page. Or you use some Javascript via data attributes. Or session data. I think referrrers are not reliable.

Edit: If I think about it, you are already passing the parent via the category, right? So if param(‘category’) is privateview, the parent is the privateview page? Then that would solve it.

yes I am passing param category privateview already -
so I need help with the link code to include it.
I am sure it is some variation of what I have but I am struggling a bit with brain fog!

On your details page, get the parameter and try to fetch the page depending on this parameter. You might have to adapt the logic.

$param = param('category');
// get the "parent" pages
$parent = null
if (empty($param) {
  $parent = page('artworks');
} else {
  $parent = page($param);
}

$url = $parent ? $parent->url() : ''; // or some default page url as fallback

will give this a try thank you so much

will give this a try thank you so much