Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
new-on-github opened this issue May 2, 2024 · 4 comments
Closed

Comments

@new-on-github
Copy link

new-on-github commented May 2, 2024

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.

@PhrozenByte
Copy link
Collaborator

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

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

@new-on-github
Copy link
Author

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?

@new-on-github
Copy link
Author

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!

@PhrozenByte
Copy link
Collaborator

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants