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

Access previous saved data in blueprint

Started by Patrick Hoehn 8 years ago · 4 replies · 698 views
8 years ago

Hey,

How can I access previous saved data in the same page blueprint? For example I have a page blueprint where I can enter a value into a text field, hit save and then I want to access this value in a drop down or select field. I tried it with 'data-options@' and several API paths but I always get an empy field or an crikey 😦

last edited 07/26/18 by Patrick Hoehn
8 years ago

@Paddi, If you want to access the value of another field in the theme's blueprint, you can do the following:

blueprints.yaml

YAML
form:
  fields:
    mytext:
      type: text
      label: My Text
    myselect:
      type: select
      label: Show value of 'mytext' in options
      options:
        'an option': an option
      data-options@: '\Grav\Theme\MyTheme::getOptions'

mytheme.php

PHP
public static function getOptions()
{
    $grav = Grav::instance();
    $config = $grav['config'];
    $mytext = $config->get('theme.mytext');

    return ["$mytext" => $mytext];
}

Unfortunately, this approach doesn't work as well as you might like:

  • The form needs to be saved twice before field 'myselect' will pickup the entered value of field 'mytext'.
  • If you saved a value for 'myselect', then update the value for field 'mytext' and save again 2 times, Grav will throw a validation error on the 'myselect' field.

There may be better/easier solutions, but I'm not aware of them yet...

8 years ago

@pamtbaau, thank you for your answer. I wrote theme blueprint but I meant page blueprint, sorry :/ I will edit it above. Is there a similar approach to this with pages? I don't know how to access the data of the currently edited page in the admin panel.

8 years ago

I have another page blueprint where I need something like this. The user should be able to pick a folder or parent page as source for an article list, hit save and then have the ability to choose which one of its children should bei highlighted or pinned. Sure I could just use two page fields with all pages in both but that would not be very user friendly. What is the right approach to this or is it simply impossible with input modules designed in yaml? This would be very limiting 😦

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1139 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 137 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 112 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 131 7 months ago