kirby-deprecated-plugins / kirby-blueprint-reader

Kirby Blueprint Reader for Kirby CMS
MIT License
13 stars 1 forks source link

repeated calles within snippet yield wrong values #13

Open bnomei opened 6 years ago

bnomei commented 6 years ago

using getting lots values directly after another does not work. only first value is returned in all cases. i am tying to print out a blueprint global select field options label (using kirby builder $data to build the string). using this within a snippet.

// $data from kirbybuilder. $data->myfield() return fieldname as string.

// A) in first call of snippet this happens. myfield() -> 'hello'
$opt1 = b::blueprint('fields/myselect', 'options/' . $data->myfield() );

// B) in another call of snippet this is called again. myfield() -> 'world'
$opt1 = b::blueprint('fields/myselect', 'options/' . $data->myfield() );

but case B) returns label value for hello where label value for world would be correct.

maybe the caching is broken? can i turn if off somehow?

jenstornell commented 6 years ago

These are identical so they will return the same value:

$opt1 = b::blueprint('fields/myselect', 'options/' . $data->myfield() );
echo $opt1;

$opt1 = b::blueprint('fields/myselect', 'options/' . $data->myfield() );
echo $opt1;

You mean that you change myfield between them?

What do you get when doing this? I don't know if it make sense in your case tho:

$opt1 = b::blueprint('fields/myselect', 'options/hello');
echo $opt1;

$opt1 = b::blueprint('fields/myselect', 'options/world');
echo $opt1;
bnomei commented 6 years ago

yes, the value of $data->myfield() changes between calls. the snippet calls the blueprint-reader-plugin but it does not depend on being within a snippet. calling them right one after another produces the error as well. not using the magic function but providing a real string for step does not change the result. it always yields the label of the first option.

i am testing this on Mac MAMP Pro, apache 2, php 5.6. but that should not really matter, right?

blueprint global field def

label: Spaltenbreite
type: select
default: 'w-full'
options:
  w-full: 100%
  w-3_4: 75%
  w-2_3: 66%
  w-1_2: 50%
  w-1_3: 33%
  w-1_4: 25%

in any template

echo b::blueprint('fields/colsize', 'options/w-1_3'); // 33%, ok
echo b::blueprint('fields/colsize', 'options/w-full'); // 33%, fails – should be 100%

❓ maybe using fields/colsize instead of a template name is wrong?

jenstornell commented 6 years ago

It looks like good information in order to track this problem down. I'm on another project right now that I need to finish so I can't work with this plugin at the moment.

If you need to get it working now, maybe this could work print_r(b::blueprint('fields/colsize'));. If it output a correct array you can step in the array to get what you want.