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

Custom field not showing up #91

Open
stephan-strate opened this issue Dec 10, 2020 · 6 comments
Open

Custom field not showing up #91

stephan-strate opened this issue Dec 10, 2020 · 6 comments
Assignees
Labels
documentation question Further information is requested

Comments

@stephan-strate
Copy link

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.

@mahagr
Copy link
Contributor

mahagr commented Dec 11, 2020

Can you give an example for me to work with? Saves some time if I know exactly what you're doing. Thanks.

@stephan-strate
Copy link
Author

stephan-strate commented Dec 11, 2020

Sure! We have got a standard theme (generated using the devtools).
Created custom form field like this:
image

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

@mahagr
Copy link
Contributor

mahagr commented Dec 23, 2020

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';
    }

@mahagr mahagr added question Further information is requested documentation labels Dec 23, 2020
@stephan-strate
Copy link
Author

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.

@phmg701
Copy link

phmg701 commented Mar 11, 2021

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: getgrav/grav#3255
I'll do tests as soon as 1.7.8 gets releases.

Hope this helps!

@mahagr
Copy link
Contributor

mahagr commented Mar 12, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants