Display select element in order

Hi,

I use a select field, to organize by category my projects.
I display this categories as a menu to browse between projects categories.
For the moment, the categories are displayed in the order of the projects publication.

<?php foreach ($pages->find('projets')->children()->listed()->pluck('category', ',', true)   as $category): ?>
        <a id="<?php echo html($category)?>"
          data-link="<?= url($site, ['params' => ['category' => $category]])?>/<?= html($pages->find('projets')) ?>"
          onclick="loadDoc('<?= url($site, ['params' => ['category' => $category]])?>/<?= html($pages->find('projets')) ?>', getCategory);">
          <?php echo html($category) ?>
        </a>
      <?php endforeach ?>

I wan’t to display the categories in the same order as I had write in my blueprint.

category:
        label: category
        width: 1/3
        required: true
        type: select
        options:
          rassembler: gather
          habiter: live
          collaborer: collaborate
          chercher: search

I’ve no clue how I can do that, do you have any leads ?

thanks

// get option keys from blueprint
$options = array_keys($page->blueprint()->fields()['category']['options'] ?? []);
// pluck used categories from children
$categories = page('notes')->children()->pluck('category', ',', true);
// get the intersection of both arrays in the order of the first array
$categories = array_intersect($options, $categories);
foreach ($categories as $category):
  // rest of code
endforeach;

I add this line in my default.php template where I want to display my categories list. but nothing is display.

<?php if($kirby->language() == 'fr')
      $options = array_keys($page->blueprint()->fields()['category']['options'] ?? []);
      $categories = page('projets')->children()->pluck('category', ',', true);
      $categories = array_intersect($options, $categories);
      foreach ($categories as $category):
      ?>
      <a>  <?php echo html($category) ?></a>
    <?php endforeach; ?>

Do the children of the project’s page use the default.yml blueprint? If not, then $options won’t return anything and you would have to get the fields from the first child, or create a manual array instead (which would probably make sense for only 4 possible options.

This how its structure works site > projects > project. My categories are in the project.yml, indeed that’s why I cannot get the blueprint options… I don’t really know how I can create an manual array

$options = [
   'rassembler',
   'habiter',
   'collaborer',
   'chercher',
];

Ah okay :grimacing:
Thanks