kirby-meta icon indicating copy to clipboard operation
kirby-meta copied to clipboard

Support meta_title overrides from page model

Open srijan opened this issue 9 months ago • 6 comments

WIP: Does not support preview yet.

Ref #37.

My use case: in some types of pages, I don't want to append title separator and site title to the page title.

One alternative implementation is to provide a boolean in the pageModel->metadata() function that controls whether to append the site title to the page title.

Let me know if you want me to change the implementation.

srijan avatar Nov 13 '23 21:11 srijan

@srijan Thanks for your contribution, I had this situation as well and have been looking for a better solution for quite some time. Your solution solves the problem quite well, though I am wondering whether we could find something a bit more elegant?

Since Kirby 4 will be released soon, I think a breaking change would be easier to justify at this point if this will land in a future release of the plugin.

fabianmichael avatar Nov 16 '23 20:11 fabianmichael

Actually, I tested this with Kirby 4, and looks like it fails with some error, so we can hold off on this implementation for now.

Do you have any ideas on any better ways to implement it?

srijan avatar Nov 17 '23 02:11 srijan

For reference, this is the error returned if I keep the Field return type:

TypeError thrown with message "FabianMichael\Meta\PageMeta::get(): Return value must be of type Kirby\Cms\Field, Kirby\Content\Field returned"

Stacktrace:
#37 TypeError in /var/www/html/site/plugins/meta/src/PageMeta.php:82
#36 FabianMichael\Meta\PageMeta:get in /var/www/html/site/plugins/meta/src/PageMeta.php:427
#35 FabianMichael\Meta\PageMeta:title in /var/www/html/site/plugins/meta/snippets/general.php:1
#34 include in /var/www/html/vendor/getkirby/cms/src/Filesystem/F.php:425
#33 Kirby\Filesystem\F:loadIsolated in /var/www/html/vendor/getkirby/cms/src/Filesystem/F.php:364
#32 Kirby\Filesystem\F:Kirby\Filesystem\{closure} in /var/www/html/vendor/getkirby/cms/src/Filesystem/F.php:372
#31 Kirby\Filesystem\F:load in /var/www/html/vendor/getkirby/cms/src/Toolkit/Tpl.php:36
#30 Kirby\Toolkit\Tpl:load in /var/www/html/vendor/getkirby/cms/src/Template/Snippet.php:172
#29 Kirby\Template\Snippet:factory in /var/www/html/vendor/getkirby/cms/config/components.php:301
#28 Kirby\Cms\Core:{closure} in /var/www/html/vendor/getkirby/cms/src/Cms/App.php:1553
#27 Kirby\Cms\App:snippet in /var/www/html/vendor/getkirby/cms/config/helpers.php:531
#26 snippet in /var/www/html/site/plugins/meta/snippets/meta.php:8
#25 include in /var/www/html/vendor/getkirby/cms/src/Filesystem/F.php:425
#24 Kirby\Filesystem\F:loadIsolated in /var/www/html/vendor/getkirby/cms/src/Filesystem/F.php:364
#23 Kirby\Filesystem\F:Kirby\Filesystem\{closure} in /var/www/html/vendor/getkirby/cms/src/Filesystem/F.php:372
#22 Kirby\Filesystem\F:load in /var/www/html/vendor/getkirby/cms/src/Toolkit/Tpl.php:36
#21 Kirby\Toolkit\Tpl:load in /var/www/html/vendor/getkirby/cms/src/Template/Snippet.php:172
#20 Kirby\Template\Snippet:factory in /var/www/html/vendor/getkirby/cms/config/components.php:301
#19 Kirby\Cms\Core:{closure} in /var/www/html/vendor/getkirby/cms/src/Cms/App.php:1553
#18 Kirby\Cms\App:snippet in /var/www/html/vendor/getkirby/cms/config/helpers.php:531
#17 snippet in /var/www/html/site/snippets/framework.php:7
#16 include in /var/www/html/vendor/getkirby/cms/src/Filesystem/F.php:425
#15 Kirby\Filesystem\F:loadIsolated in /var/www/html/vendor/getkirby/cms/src/Filesystem/F.php:364
#14 Kirby\Filesystem\F:Kirby\Filesystem\{closure} in /var/www/html/vendor/getkirby/cms/src/Filesystem/F.php:372
#13 Kirby\Filesystem\F:load in /var/www/html/vendor/getkirby/cms/src/Toolkit/Tpl.php:36
#12 Kirby\Toolkit\Tpl:load in /var/www/html/vendor/getkirby/cms/src/Template/Snippet.php:248
#11 Kirby\Template\Snippet:render in /var/www/html/vendor/getkirby/cms/src/Template/Snippet.php:132
#10 Kirby\Template\Snippet:end in /var/www/html/vendor/getkirby/cms/config/helpers.php:152
#9 endsnippet in /var/www/html/site/templates/home.php:95
#8 include in /var/www/html/vendor/getkirby/cms/src/Filesystem/F.php:425
#7 Kirby\Filesystem\F:loadIsolated in /var/www/html/vendor/getkirby/cms/src/Filesystem/F.php:364
#6 Kirby\Filesystem\F:Kirby\Filesystem\{closure} in /var/www/html/vendor/getkirby/cms/src/Filesystem/F.php:372
#5 Kirby\Filesystem\F:load in /var/www/html/vendor/getkirby/cms/src/Toolkit/Tpl.php:36
#4 Kirby\Toolkit\Tpl:load in /var/www/html/vendor/getkirby/cms/src/Template/Template.php:163
#3 Kirby\Template\Template:render in /var/www/html/vendor/getkirby/cms/src/Cms/Page.php:1017
#2 Kirby\Cms\Page:render in /var/www/html/vendor/getkirby/cms/src/Cms/App.php:777
#1 Kirby\Cms\App:io in /var/www/html/vendor/getkirby/cms/src/Cms/App.php:1191
#0 Kirby\Cms\App:render in /var/www/html/public/index.php:18

srijan avatar Nov 28 '23 13:11 srijan

@srijan I am aware of this issue … the namespace of Field has changed with v4. I want to release a final version of the plugin for 3.x and a 2.0 version for Kirby 4 as soon as possible. But there’s no reason the remove the type check can be added again for the v4-specific version.

fabianmichael avatar Nov 28 '23 13:11 fabianmichael

@srijan Thanks, will look into this soon. Please have a bit of patience. Just released a 1.0.0 as final version for Kirby 3.

fabianmichael avatar Nov 28 '23 14:11 fabianmichael

@srijan Thanks, will look into this soon. Please have a bit of patience. Just released a 1.0.0 as final version for Kirby 3.

Please don't feel pressured. Take your time :+1:

srijan avatar Nov 28 '23 15:11 srijan