Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

How to add an extra content field

Started by Muut Archive 10 years ago · 11 replies · 1068 views
10 years ago

I would like some of my posts to contain an extra field, called subhead. Ideally, this would be presented through Admin in Add Page. I can see where the field ought to go in /system/blueprints/pages/default.yaml but I am not sure how to modify that in my own theme, which is a child theme of Antimatter.

I can see how to add a completely new tab, or add the field I want to the Blog Item tab using a blueprint.yaml file, but it would be a lot neater if I could add the field to the Content tab.

Is there an example of extending the default.yaml within a child theme? Or do I create a new default.yaml, and if so, where?

Thanks

10 years ago

You need to add a new page template file and define new fields for the content tab, for example:

default2.yaml

YAML
title: Default2
'@extends': default

form:
  fields:
    tabs:

      fields:
        content:
          type: tab

          fields:
            header.test:
              label: Enter something
              type: text
10 years ago

Thanks.

Unlike the other blueprint files, this one does not seem to have the context: element. Does that matter?

10 years ago

That's the default location where to "lookup" the default file, so you can omit it.

10 years ago

Great. Thanks for your help and explanation.

10 years ago

Sorry, I'm back. I managed to get exactly what I wanted only by adding the extra field in the default.yaml. But that's no good in the event of updates.

I copied the default.yaml into mytheme/blueprints but it didn't seem to work there.

For neatness, I wanted the extra field to be in the existing Content tab, but I just don't seem to be able to get that. I'll try a completely new tab next.

10 years ago

I just copied the default.yaml into my new blueprint, and just grabbed what I wanted and removed the rest. Then I had full control of the content tab etc.

10 years ago

Interesting. I did the same and it wouldn't work for me. Did you rename the default.yaml?

10 years ago

I made .yaml that matched the name of the new template I'd created. So for example if you have a blog.html.twig in your templates folder, then you create a blog.yaml file in the blueprints. I'm not sure how you would go about overriding the default.yaml/default.html.twig, I'd recommend just creating a new template entirely.

10 years ago

Ah, OK. I misunderstood you to say that you duplicated the actual default.yaml.

10 years ago

Sorry, I meant I just copied the content into a new .yaml file, and made the appropriate changes. Hope you manage to fix your issue.

10 years ago

I added a field for quotes in a new yaml file. The field is visible but the content is not saved.

YAML
title: Page with quote
'@extends': default

form:
  fields:
    tabs:

      fields:
        content:
          type: tab

          fields:
            quote:
              label: Quote
              type: text
              title: Quote

In the template I put

TWIG
{% block quote %}
    {{ page.quote }}
{% endblock %}  

This is what the page source in admin looks like:

HTML
<div class="form-data block size-2-3" data-grav-field="text" data-grav-disabled="true" data-grav-default="null">
                                                            <div class="form-input-wrapper ">
                            <input name="quote" value="" title="Quote" type="text">
                        </div>
                                                </div>

Does this has something todo with entered text not being saved?

TXT

 data-grav-disabled="true"
---

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1359 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2956 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago