Changed blueprint: Is there an easy way to update all pages of that blueprint?

Hi together,
is there an easy way to update all page content according to the blueprint? I added a field to a structure of a blueprint. Now I get an error when accessing the new field in a template. The only way to resolve this is to manually go through all pages using that blueprint, editing and saving the structure entries so they have the field.

You can do this programmatically with a little script, yes.

You could you this addToStructure() method and adapt it to your purpose:

function addToStructure($page, $field, $data = array()){
      $fieldData = page($page)->$field()->yaml();
      $fieldData[] = $data;
      $fieldData = yaml::encode($fieldData);
      try {
        page($page)->update(array($field => $fieldData));
        //return true;
      } catch(Exception $e) {
        return $e->getMessage();

(make a backup of your data before you test anything)

Thanks for the quick reply! Also I realized the .txt file still has removed field content, it would be nice to remove that too as soon as the field is removed from the blueprint.

Whats the best/nicest way to execute a script like that?

That depends, for a one time thing, I usually do it quick and dirty in a template and remove afterwards.

For something that you might need regularly, a script that you call via a route or directly from the filesystem might be an option.

Here is a cleaning up recipe for Kirby 3: (you can’t use this for because Kirby 2 doesn’t have a blueprint method, so you would have to come up with an adapted solution).

Great thank you. I was thinking of a route as well, but the template sounds like the easiest solution.