Including a php array, but not everywhere

Hi there :slight_smile:

I need to include a lengthy array in only some templates/snippets.

As I understand I could add this array as a plugin and kirby would include it automagically everywhere.

I assume this somehow loads the array in every page tho. At least network-transfer-wise. Is this correct ?

If it is, is there a way to only include the array in selected templates/snippets as described ?

Thank you.

The best option is to return the array from a function; or you can define it in a c::set() method in. your config.

1 Like

So something like this:

plugin.php

<?php
    function myarray(){
      return myarray(
        "this" => "bar",
        "that" => "foo"
      );
    }

templateorsnippet.php

  <?php $herearray = myarray() ?>

Exactly (and some more chars)

Other options would be to define them as a constants or create a class with static variables.

1 Like