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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

How to automatically enable an override in a blueprint?

Started by paul 6 years ago · 6 replies · 660 views
6 years ago

I'm working with a theme that inherits from Quark. I'd like new blog posts to automatically be set to visible: false. I've copied item.yaml to my inherited theme and added the following:

TWIG
        advanced:
          fields:
            overrides:
              fields:
                header.visible:
                  default: 0

In admin, the check box next to the page visibility override is left unchecked as seen in the attached image. Is there a way I can specify that this override should be checked/enabled?

image|690x65

6 years ago

@prw, Presuming the folders containing a blog item do not have a numeric prefix, shouldn't items be invisible by default? Or are numeric prefixes used in your use-case? See variable visible.

By default, a page is visible in the navigation if the surrounding folder has a numerical prefix, i.e. /01.home is visible, while /error is not visible .

Anyway, if you add toggleable: false it should force adding visible: false to the header of the page.

6 years ago

@pamtbaau, Thanks for your reply. I did try toggleable: false, and while it removes the checkbox next to the "Visible" item in admin, it does not enter visible: false to the page header. I have to manually click "Disabled" in admin and save again for the header to change. (Edit: To clarify, "Disabled" shows up as selected, but still needs to be clicked and saved to work.)

Thanks for the heads up about the numeric prefix. I didn't notice that that's a blog setting that can be enabled or disabled. I may want to keep numeric prefixing, though. So it would still be nice to find a solution to this that makes visible: false to be applied fully automatically.

6 years ago

@prw,

For my previous answer, I did the following steps using the 'Blog Site' skeleton and theme 'mytheme' inheriting from Quark:

  • Copied 'themes/quark/blueprints/item.yaml' to 'themes/mytheme/blueprints/item.yaml'
  • Replaced the contents of 'item.yaml' with:

    YAML
    extends@: item
    
    form:
    fields:
      tabs:
        fields:
          advanced:
            fields:
              overrides:
                fields:
                  header.visible:
                    toggleable: false
                    default: 0
    
  • Added new blog item 'My new blog item' with root 'Home' and page template 'Item', leaving everything else to their default values.
    The field 'visible' looks as follows
    image|568x128
  • Saved new blog item.
  • Header of page '01.home/my-new-blog-item/item.md':
    YAML
    ---
    title: 'My new blog item'
    visible: false
    feed:
      limit: 10
    ---
    

To mimic your use-case with numeric prefixes for blog items:

  • Copied folder '01.blog' to '02.blog2'
  • Prefixed 2 blog items with numbers and removed the others.
  • Created new blog item 'Prefixed blog item', with root 'Home2' and template 'Item', leaving everything else to their defaults.
  • Saved blog item
  • Header of '02.blog2/03.prefixed-blog-item/item.md' is:
    YAML
    ---
    title: 'Prefixed blog item'
    visible: false
    feed:
      limit: 10
    ---
    

In both use-cases, the header is set to visible: false.

6 years ago

Thanks, @pamtbaau for your reply and taking the time to do a test case. I've been away from the project for a few days, and just coming back to it.

I tried repeating your steps with a fresh download of Quark and could not replicate your results. Until I tried with grav 1.6.x. Then it works as you demonstrated.

I have been using the 1.7 RC and it does not work. Do you think that's a bug?

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1140 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 63 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 138 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 114 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 132 7 months ago