picocms/Pico

Question: How to use page yaml-header meta-data in php for a plugin?

new-on-github opened this issue · 4 comments

Hello all together,

I'm using pico with the pico-rssmaker:
https://github.com/MattByName/Pico-RssMaker
https://github.com/MattByName/Pico-RssMaker/blob/master/RssMaker.php
it works fine.
Now I want to add a image to the other sub items of the rss-feed:

//Page loop
            foreach ($reverse_pages as $page) {
                if (!empty($page['date']) && !$page['hidden']) {
                    $rss .= '<item>';
                    $rss .= '<title>';
                    $rss .= $page['title'];
                    $rss .= '</title>';

                    $rss .= '<description>';
                    $rss .= $page['description'];
                    $rss .= '</description>';

                    $rss .= '<link>';
                    $rss .= $page['url'];
                    $rss .= '</link>';

                    $rss .= '<pubDate>';
                    $rss .= date(DATE_RFC2822, $page['time']);
                    $rss .= '</pubDate>';

                    $rss .= '<guid>';
                    $rss .= $page['url'];
                    $rss .= '</guid>';

                    $rss .= '</item>';
                }

Now some of the meta-data of the yaml-header:

--- 
title: my title
date: ...
style: blog
description: my description
image: %assets_url%/path-to-image
hidden: false
mastodon: false
--- 

can be accessed via $page['meta-item-name']; in php. But this works only with title, description but not with my own meta-tags and also not with the image-tag.
I tried this:

$rss .= '<enclosure url="';
$rss .= $page['image'];
$rss .= '"/>';

But this doesn't work.

I already asked the maintainer of Pico-RssMaker. He tried to help, but there is still no solution:
MattByName/Pico-RssMaker#6

Does someone know how to access the meta-data-items in php?

Thanks al lot.

Try $page['meta']['image'] 👍

Only basic meta data (like titles) can be accessed directly via e.g. $page['title']. I know, it's confusing...

Thanks a lot, this works now.

But there is now a other problem: It gives not the correct link back. Instead of https://my-domain/path-to-image it gives
%assets_url%/image
back.
Can this also be solved without giving the full correct path in the meta-data-tag?

Ok, thinking before asking would help...

I could achieve this in php with the following code:

                    $rss .= '<enclosure url="';
                    $rss .= str_replace('%assets_url%', $this->baseURL."assets", $page['meta']['image']);
                    $rss .= '"/>';

Thanks a lot for the help and for pico cms!

Instead of https://my-domain/path-to-image it gives %assets_url%/image back.

Try $this->getPico()->substituteUrl($page['meta']['image']) instead (it's the same as Pico's url Twig filter).