Comments (3)
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.
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.
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)
- Kirby 3: template settings override defaults instead of being merged HOT 3
- First argument should be a Page HOT 4
- JSON-LD not working with meta-tags.templates HOT 7
- link alternate error HOT 3
- Author toUser() breaking on pages not related to it's template type HOT 1
- og:tag - ErrorException: time() expects exactly 0 parameters HOT 1
- languages are collected from wrong object HOT 1
- documentation โย fields not present for specific sources
- Alternate hreflang HOT 2
- Works only for one page
- Each call to render bloats up with duplicate tags
- Pass Kirby object to config function
- 3.8 compatibility
- Please Upgrade for Kirby 3 ASAP! ๐ HOT 3
- PHP 8.2 Creation of dynamic property is deprecated HOT 1
- K3 version not working with latest beta HOT 3
- Access to method Children HOT 5
- How to define multiple preconnect and prefetch links? HOT 3
- JSON+LD Collections
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kirby-meta-tags.