grav-plugin-flex-objects
grav-plugin-flex-objects copied to clipboard
Custom field not showing up
We have added a custom form field in our theme, its working in regular page blueprints. Adding it to a custom flex object form, it does not even show up.
Maybe this has something to do with flex object being initialized earlier? I could not add flex object definitions in our theme either, needed to add it in a plugin.
Can you give an example for me to work with? Saves some time if I know exactly what you're doing. Thanks.
Sure! We have got a standard theme (generated using the devtools).
Created custom form field like this:
documentation.html.twig
{% extends 'forms/field.html.twig' %}
{% block contents %}
some output
{% endblock %}
Added template path in my-theme.php like this:
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
flex-object form field:
title: Contacts
description: Contacts
type: flex-objects
extends@:
type: contacts
context: blueprints://flex-objects
form:
validation: loose
fields:
documentation:
type: documentation
Yeah, because frontend templates are not being loaded in admin -- they break admin if you do so.
Move fields into admin/templates
and use onAdminTwigTemplatePaths
event:
public function onAdminTwigTemplatePaths(Event $event)
{
$paths = $event['paths'];
$paths[] = __DIR__ . '/admin/templates';
}
Got it! Is there a similar strategy to add the flex object blueprints in themes? I got it working in user/blueprints
and in the plugins blueprints folder, but not in theme right now.
Got it! Is there a similar strategy to add the flex object blueprints in themes? I got it working in
user/blueprints
and in the plugins blueprints folder, but not in theme right now.
Hello, I had the same question and it now seems fixed in next 1.7.8 release: https://github.com/getgrav/grav/issues/3255 I'll do tests as soon as 1.7.8 gets releases.
Hope this helps!
Yup, the missing blueprints issue has also been fixed, but you need to move the files around (to follow the same blueprints folder structure as in plugins) to enable it.