Get the URL/name/description of a Project from a list of Projects

Hi, thanks for any help in advance, i’m a great noob with PHP.

I need to make a list of projects in the homepage. I ended up with a foreach that fetches dynamic content for… well, each… anchor that i want to see listed. This content comes from the homepage content file (txt); i have a list of projects there.

Now i was about to get the URL, but it might change if i rename the folders. What is the smart way to guess the name, URL and description of each project? How do i fetch the information from the project itself instead of the source content file?

From what I understand you have a projects folder with your projects subpages.

Then in your homepage, you store references to some of these project subpages to display them on the homepage, right?

If that is correct, the best way to prevent issues with folder-renaming is to use the AutoID plugin which gives each page a unique reference and then to store this reference instead of the project’s URI.

That’s right, i have a folder/subfolder structure. Then in the homepage content file i listed the information to fill in the acnchors (href, class, title, content). In the homepage template i have 1 anchor inside a foreach.

Thanks, looks like a powerful plugin. I would like to still try without attaching more external code. I like to commit myself to the original logic and go with it in the best way possible. I guess i’ll have to use the plugin when the list goes wild and longer than what already is…

Just trying to grasp more of the Kirby’s basics… So, the “standard” approach would be to use the URI? Is the URI the path to the folder? So, Kirby’s logic is to store anchor information in the page’s content file?

The URI is the unique path to the subfolder, so that Kirby can find it from anywhere, no matter your nesting level. You store this path in the content file, then you can fetch the page from that information.

The thing to keep in mind is that this information is not updated when pages are renamed or deleted, that’s why many of use use the autoID plugin. The alternative to using a plugin would be to store some sort of manual permanent link within each page, but then again, you would have to make sure that this reference exists only once.

Success! Thank you! I guess this will work fine for now:

<?php $project = $pages->find('projects')->children(); ?>
<?php foreach($project as $item): ?>
    <a xlink:href="<?= $item->url() ?>" class="<?= $item->anchor_class() ?>" x="16" y="16">
        <title><?= $item->anchor_title() ?></title>
        <circle class="stroke" cx="-5" cy="-2" r="2.5"/>
        <text><?= $item->anchor_text() ?></text>
<?php endforeach ?>