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.

Archive

Blueprint form to control what is displayed on a page

Started by Muut Archive 9 years ago · 2 replies · 568 views
9 years ago

Going over the Blueprint documentation and I'm not sure if its possible but lets say I have a page with 9 pictures/divs and I would like the user to be able to login into the admin and be able to enable or disable those images/elements from being displayed with a toggle button on the form. Is that possible with a blueprint for a theme/page? Basically the page is kind of like something being in stock or out of stock and I would want the user to easily update the page with a form within the admin.

9 years ago

I would use a list of images paired with a toggle (if that is possible)

Something like this

YAML
header.products:
   name: products
   type: list
   style: vertical
   label: Products
   fields:
      .inStock:
         type: toggle
         label: Product In Stock
         highlight: 1
         default: 1
         options:
            1: PLUGIN_ADMIN.YES
            0: PLUGIN_ADMIN.NO
         validate:
            type: bool
      .image:
         type: file
         label: Product Image
         multiple: false 
         destination: 'path/to/folder'
         accept:
            - image/*

and the template

TWIG
{% for product in page.header.products %}
   {% if product.inStock %}   
      <div class='product'>
         {% for image in product.image %}
            <img src='{{ image.path }}' />
         {% endfor %}
      </div>
   {% endif %}
{% endfor %}

Hope that helps!

9 years ago

Something like this should work, I would think. Have you tried it?

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1282 9 years ago
Archive · by Muut Archive, 9 years ago
2 889 9 years ago
Archive · by Muut Archive, 9 years ago
2 4019 9 years ago
Archive · by Muut Archive, 9 years ago
1 2894 9 years ago
Archive · by Muut Archive, 9 years ago
3 1078 9 years ago