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

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):

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? :slight_smile:

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

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

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 Like

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!

If it can help anyone regarding domsson’s last question (meaning and use of blueprints:// aka PHP streams) :
https://learn.getgrav.org/15/content/image-linking#php-streams
https://www.php.net/manual/en/intro.stream.php

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;

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 Likes

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! :heart_eyes: