GithubHelp home page GithubHelp logo

Comments (3)

bvdputte avatar bvdputte commented on May 27, 2024 1

No problem! I think I'm the one owing an apology tbh...
Upon seeing your sample code I noticed I most probably have implemented it wrong ๐Ÿ™ˆ.

I used closures on the templates instead of the options.

First I tried to implement it as following:

return [
    // other options...
    'pedroborges.meta-tags.templates' => function($page, $site) {
        return [
            'article' => function($page, $site) {
                return [
                    'og' => [
                        'type' => 'article',
                        'image' => $page->heroimage()->toFile()->url(),
                    ]
                ];
            },
        ];
    },
];

I've altered my code to your sample code, but removing the closures on the templates and putting them on the options:

return [
    // other options...
    'pedroborges.meta-tags.templates' => function($page, $site) {
        return [
            'article' => [
                'og' => [
                    'type' => 'article',
                    'image' => function($page, $site) {
                        if ($img = $page->heroimage()->toFile()) {
                            return $img->url();
                        }
                        return "";
                    }
                ]
            ],
        ];
    },
];

and now it seems to work, so I think it's intended to work like this. Right?
If it is, you can surely dismiss my PR.

from kirby-meta-tags.

bvdputte avatar bvdputte commented on May 27, 2024

FYI: Seems like replacing this with the following "fixes" it somehow:

if (isset($templates[$page->intendedTemplate()])) {
    $tagsForTemplate = $templates[$page->intendedTemplate()];
    $tagsForTemplate = is_callable($tagsForTemplate) ? $tagsForTemplate($page, site()) : $tagsForTemplate;
    $this->data = a::merge($this->data, $tagsForTemplate);
}

It's just an extra test to see if the passed array item is also a closure.

from kirby-meta-tags.

pedroborges avatar pedroborges commented on May 27, 2024

I apologize for taking so long to review this. I think there's a misunderstanding, but please let me know if you think I'm wrong ๐Ÿ˜‰

Tag groups are title, meta, link, og, and twitter. Those work with closure from the beginning. After a while, I realized it would be better to accept a closure on the options. Then I added support for:

<?php

return [
    // other options...
    'pedroborges.meta-tags.templates' => function($page, $site) {
        return [
            'article' => [
                'title' => $page->title(),
                'og' => [
                    'title' => $page->title()
                ],
            ],
            'about' => [ /* tags groups */ ],
            'products' => [ /* tags groups */ ],
        ];
    },
];

Is that what you are trying to achieve?

from kirby-meta-tags.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.