Lack of comprehension on how to call specific content in specific pages

Hello, once again…, I’ve got 2 questions I hope they are related, as far as I don’t get the logical way on how to do each of them.

I’ve got 10 pieces, 5 are prods-outside, 5 prods-inside, and I put all the prods as children of the archive file.

1_productions
	1_productions-outside
	2_productions-inside
	3_productions-archives 

How to call the prods-outside and -inside from the archives?
Once again I’m thinking « maybe I need to add a toggle to indicate which file is part of which category… or a tag and then filter by tag or toggled.
And then I will have a snippet per page inside and outside, each one calling the pieces with tag. But that don’t seem right and elegant, what is the better way to do it? Thank you for your help

I’m using this snippet

<?php if ($page = page('productions')->children('productions-archives')): ?>
<?php foreach ($page->children()->listed() as $piece): ?>
  <a href="<?= $piece->url() ?>">
  <h1><?= $piece->title() ?></h1>
  </a>
<?php endforeach ?>
<?php endif ?>

My related question is, how the user call a page to put on the home, it’s not a page that is actuality in relation to a date, but for various reasons a page or another he might want to put in highlight on the homepage? What is the right way in the yaml file to add a field the user can trigger so the file can be add to the home page? toggle, tag or antohter method? Thanks again

Let’s start with the second one, because that’s easier. I’d use a pages field (lets call it highlight in the home blueprint where the user can select any page. Then in your home template:

if ( $highlightPage = $page->hightlight()->toPage()) {
  echo $hightlightPage->title();
}

As regards the first question, why are the productions in a separate archive folder and not in there respective folders?

I created such a setup recently using models, but to be more flexible, I created the categories as virtual pages as well and locked the pool, so that the pages are not accessible via multiple URLs.

Hello @texnixe, thank you for your help, so on the second one:
if I understand you in the panel of the home the user will be able to choose anypage she likes? then how does the yaml for the highlight look, what is its type, is it a query or else? (it sounds amazing but I don’t know how to do such things…)

Depends what you want, in its most simple form (which will let the user select from all pages)

fields:
  highlight:
    type: pages

You can use a query to limit the selection.

(h)oooookay, thank you I will try that

Woawww! This is amazing! Thank you very much (that opens a new fields of possibility)

Because some productions are first normal prods, but then they might be classified in the special category inside or outside, and if they are they will at least appear in the archive. So for me it first mades more sense to have all prods in the archive, and call the special ones in one of the 2 category.
Now I see how I might call them in those categories with the type: pages field. But if there is more logical way to do it I’m happy to change my view. (these days learning kirby, yml, md, zettelkasten, is so much reformulating my mind, I try to trade bricolage for logical blueprints…)

As I already mentioned above, the thing to avoid is duplicated content, so the same page (as a single page) should not be available under different URLs. Of course you can show a filtered collection on the productions-outside and productions-inside pages, by adding a category select field to each subpage of the archive page and select one of the two categories (or none):

Then in productions-outside

$outsideProds = page('productions-archives')->children()->listed()->filterBy('category', 'productions-outside');
foreach ($outsideProds as $outsideProd) {
  // do stuff
}

Same for the inside prods. The name of the field is irrelevant, you can call it anything you want, of course.

That way, when you click on a link to one of the subpages, you would still have them under productions-archives and no problem. If that’s ok, then everything is fine.

If you want these pages to appear as if they were children of their respective virtual parents, then you have to invest more brain in the form of page models with virtual children, rewritten URLs and routes that avoid duplicate content. Which wouldn’t make sense if these subpages are supposed to change their childhood relationship at any time.

Once again, thank you for the patience. I will sleep on it (brain will first have to go to sorting dates…). Good night

I’m still fighting with basic php (less confuse but still…)
I try to use this code

<?php if ($page = page('productions')->children('productions-archives')) {
  <?php snippet('fil_archives') ?>
} else {
  echo "Collections";
} ?>

and my snippet is like this

<nav id="menu archives">
  <?php
  $Productions = page('productions')->children()->unlisted();
  if($Productions->isNotEmpty()):
  ?>
  <ul class="submenu">
    <?php foreach($Productions as $Production): ?>
    <li><h3 class="blinkus"><a<?php e($Production->isOpen(), ' class="active"') ?>
    href="<?= $Production->url() ?>"><?= $Production->title()->html() ?></a></h3></li>
    <?php endforeach ?>
    <?php endif ?>
  </ul>

Can you help me so I can understand those better, thanks.

Also on the error page I get the message " Enable debug mode to get further information about the error" but in my config.php I did but debug and and whoops on true, any idea?

That if statement doesn’t make sense. I don’t know what you want to check here, but you should actually check if the page called productions exists before you call the children() method. Note that–provided the page exists–page('productions')->children() will always return a collection even if empty.

Also, you cannot pass an argument to the children() method, so what is productions-archives, a template you want to filter by?

<?php 
$productions = null;
if ($p = page('productions')) {
  $productions = $p->children();
}

But then again, since you don’t use the $page variable, we don’t need to define it and we also don’t have to define $productions because you do that inside the snippet.

What I would do:

<?php 
// check if the page exists and if it has unlisted children, if yes, include the snippet
if ( ($p = page('productions') ) && $p->children()->unlisted()->isNotEmpty() ) {
  snippet('fil_archives', ['productions' => $p->children()->unlisted());
}

And then inside the snippet:

<nav id="menu archives">
  <ul class="submenu">
    <?php foreach($productions as $production): ?>
    <li><h3 class="blinkus"><a<?php e($production->isOpen(), ' class="active"') ?>
    href="<?= $production->url() ?>"><?= $production->title()->html() ?></a></h3></li>
    <?php endforeach ?>
  </ul>
</nav>

Could you post the complete config?

Some comments on your original code:

With your if statement after the opening nav you would end up with an empty nav element if the page doesn’t have unlisted pages, which should be avoided.

The closing if is in the wrong position and should have been after the closing ul .

To understand more, read about classes and objects in PHP.

Thanks for your answers, but I am not able to make your code work yet. I include an image of my content: the productions are unlisted in 1_productions, and collections and archives are listed.
I want to render the productions taged collections (->filterBy(‘tags’, ‘collection’, ‘,’) on the collections pages. And the archives render all the unlisted productions.
(for now I created two different template/blueprint/snippet to call the productions as collections and archives)…

What is wrong with the result of the code I posted above? Does it throw an error or not render the correct results?It’s a bit hard to follow along with your structure.

I get an error. Sorry, I think it was my first question on how to logicaly organise those files.
I choose to have all the production on first level and then call them in each subpages by tags. Maybe I should put them in each respective categories and call all unlisted in archives. I will try that for now and let you know, thank you

If you get an error, please always post the error message, where in the code the error is thrown etc. or a screenshot of the error. “I get an error” is not really super useful information… :wink:

Yes, “This page is currently offline due to an unexpected error. We are very sorry for the inconvenience and will fix it as soon as possible.”, I always get this error when I do error (lot). That why I think the debug is not working right…

Here is the config file of site:

<?php
return [
    'languages' => true
];

return [
  'smartypants' => true
];

return [
    'debug'  => true
];

return [
    'date.handler' => 'strftime'
];

Ah, that’s what I feared. All settings must be in a single return array, see the docs.

Learn about what return does to understand why: https://www.php.net/manual/en/function.return.php

:smiley: debug is working: ) instead of ]
Your code is working just fine, thanks!
but now how would you add if or else statement, to render the productions filterBy(‘tags’, ‘collection’, ‘,’) if the page is in 2_collections-permanentes?

I tried without succes variant around:

<?php if ( ($p = page('productions') ) && $p->children()->unlisted()->isNotEmpty() ) {
  snippet('fil_archives', ['productions' => $p->children()->unlisted()]);
}
else ($p = page()->children(collections-permanentes) )  {
  snippet('fil_archives', ['productions' => $p->children()->unlisted()->filterBy('tags', 'collections', ',')]);
} ?>