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

Importing blueprint does not work - what does context do / mean?

Solved by Ben Bricker View solution

Started by Julien 8 years ago · 5 replies · 1792 views
8 years ago

I'm trying to put part of a blueprint into a separate blueprint, so I can import it into several others. To do this, I followed the instructions on advanced blueprint features. I created a new folder within my theme's blueprints folder, called partials and creates a sidebar.yaml file with the tab and fields definition exactly as it previously was in my main blueprint, main_left.yaml. The main blueprint now looks like this (all content has been moved to the partial):

YAML
title: Main Left
extends@:
  type: default
  context: blueprints://pages

import@:
  type: partials/sidebar
  context: blueprints://

However, split up like this, the new tab does not appear in the admin panel.

For brevity, I'm omitting the content of sidebar.yaml, because if I add it directly into main_left.yaml (instead of the import statement), it works just fine. My assumption is that the type and/or context values are somehow wrong and Grav can't find the partial blueprint. To be honest, from the documentation, I couldn't understand what contextdoes . I sometimes see it in examples, sometimes not, it seems to work in both cases. Any enlightenment? :)

last edited 06/14/18 by Julien
8 years ago Solution

Is that your whole blueprint file?

I think the problem is you don't have the import in the right section. I'm not positive but I don't think you can import a whole tab using a partial, just the fields.

Here's an example I have that worked.

Main File

YAML
title: Main File
'@extends':
    type: default
    context: blueprints://pages

form:
  fields:
    tabs:
      fields:
        tabName:
          type: tab
          title: New Tab Name

          fields: 
            images:
              type: section
              title: images
              underline: true
              import@:
                type: partials/paritial-fields
                context: blueprints://

Partial File

YAML
form:
  fields:
    gallery.title:
      type: text
      label: Title
    gallery.images:
      type: list
      label: Images
      fields:
        .src:
          type: text
          label: Image

Like I said though, I'm not sure if you can import a whole tab. You may be able to, but I wasn't able to get that to work either.

👍 1
8 years ago

Thank you, bbricker. So it would seem there were at least two things "wrong" with my setup:

  1. I tried to import a whole tab which seems not to work
  2. I did not include the form: line in my partial template

The form: seems to be required to actually make the sub-template "whole", I guess? If I just paste its contents directly into the main template, then I don't need the form:. Anyway, it works now.

Two follow-up question if anyone knows:

  1. Is there more exhaustive documentation on blueprints anywhere? I have so many questions.
  2. One of these questions: I'm still not sure how to interpret/use the blueprints:// statement.

Cheers!

7 years ago

Which is to say that streams resolve to physical locations, expanded upon in the Multisite-setup part of the docs. So the context-property works as a prefix in the case above;

YAML
import@:
  type: partials/sidebar
  context: blueprints://

Will try to import /user/plugins/admin/blueprints/partials/sidebar.yaml, since blueprints:// by defaults resolves to Admin's /blueprints-folder.

But context: user://themes/mytheme will resolve to /user/themes/mytheme, and in conjunction with import@: type: partials/sidebar this means it tries to import /user/themes/mytheme/partials/sidebar.yaml.

There is a distinct lack of documentation about how blueprints work under the hood, it's all in code in Rockettheme/Toolbox, and since almost all failures are silenced debugging them is difficult.

👍 3
7 years ago

You're a lifesaver!
I was looking for explanation of those advanced blueprint features without luck, and thanks to this post I've managed to actually do what I planned! 😍

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1133 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 60 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 131 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 107 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 125 7 months ago