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.

Support

Blueprints issue?

Solved by Paul Massendari View solution

Started by andrii burkatskyi 9 years ago · 14 replies · 1152 views
9 years ago

Hi!
I want to have page header as below that will be make by blueprint

YAML
title: notes
content:
    items:
        '@taxonomy.category': notes

I create a simple blueprint:

TXT
title: notes
'@extends':
    type: default
    context: blueprints://pages

    form:
      fields:
        tabs:
          type: tabs
          active: 1

          fields:

            notes:
              type: tab
              title: Custom

              fields:
                header.content.items:
                  type: textarea
                  yaml: true
                  label: Items
                  default: {'[email protected]': notes}
                  validate:
                    required: true
                    type: string

And when i create a page and look to my custom tab i see

'@taxonomy.category': notes

But after i save this page i see wrong code which not works:

YAML
title: test
content:
    items: '''@taxonomy.category'': notes'

What i do wrong?

P.S: Sorry for my English)

9 years ago

{% extends 'partials/base.html.twig' %}

TWIG
{% block content %}

{% set collection = page.collection() %}

<div class="pure-g">
<div class="pure-u-1 pure-u-md-16-24 padding transition">
    <h2 class="text-center">Last Notes</h2>
    {% for child in collection %}
        {%
            set image = child.media['_header.jpg']
            ? child.media['_header.jpg']
            : child.media.images|first
        %}
        {% include 'partials/article.html.twig'  with {'child': child, 'image':image} %}
        {% if not loop.last %}
            <div>
                <hr class="note-hr"/>
            </div>
        {% endif %}
    {% endfor %}
    {% if config.plugins.pagination.enabled and collection.params.pagination %}
        <div class="pure-g">
            <div class="pure-u-1">
                {% include 'partials/pagination.html.twig' with {'base_url':page.url } %}
            </div>
        </div>
    {% endif %}
</div>
<div class="pure-u-1 pure-u-md-8-24 padding transition">
     {% include 'partials/sidebar.html.twig' %}
</div>
</div>
{% endblock %}

It works good if i write
items:
'@taxonomy.category': notes
by hand.
I just want to figure out how to write more complex structures in blueprints

9 years ago

I can't say I know how to do that with the blueprints. But if you aren't going to be changing the collection, you could use twig to get the information you need. Since the twig file will always be linked to that blueprint, it will accomplish the same thing.

{% set collection = page.collection({ 'items': { '@taxonomy': { 'category': 'notes' } }, 'pagination': true }) %}

9 years ago

Yeah, i know this way and use it now, by i want to better understand blueprints.

9 years ago

I think t's because of the yaml: true or the string validation

9 years ago

I tried to remove this lines - unfortunally, it is not helped.
It is looks like parsing issue.

9 years ago

with and without yaml: true?

9 years ago

Yes - it does not affect. When i just create a new page i see the correct code (like [email protected]: notes or '[email protected]': notes) in my custom tab. But when i save this page the code writes into a page with additioal quotes and without right indentation.

9 years ago

It's because you have to store a colon in your yaml file, and it's a special character for yaml.

If your value is stored like that:

TXT
'''@page'': ''/blog'''

It will be displayed like that in your template, which is correct.

TXT
'@page': '/blog'
9 years ago

Ok, i understand it.
If generalize the question I want to know how can i will add indents and new lines using blueprint...
If i edit page content in expert mode and write content: {items: {taxonomy@: { 'category': 'notes'}}} after saving it writes good with correct indent:

YAML
content:
    items:
        taxonomy@:
            category: notes

And I think method like this should be for blueprint

9 years ago Solution

take a look at the multilevel field.
You could also indent by writing

YAML
header.content.items.taxonomy@:
  type: array
  label: choose taxonomy

and then you write category and notes

👍 2

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 51 7 hours ago
Support · by Anna, 2 days ago
2 58 10 hours ago
Support · by Justin Young, 11 hours ago
1 30 11 hours ago
Support · by Duc , 1 week ago
2 63 5 days ago
Support · by Colin Hume, 1 week ago
2 55 5 days ago