Thank you Lulia!
To display a named array item you can reference it with a colon. For example if you had set the custom object with an array set via PHP such as:
$myvar = array ();
$myvar['color1'] = 'red';
$myvar['color2'] = 'green';
$myvar['color3'] = 'blue';
$logichop->set_data( 'myvar', $myvar );
You could use the following Logic Tags to display the values:
{{ var: Custom.myvar:color1 }}
{{ var: Custom.myvar:color3 }}
{{ var: Custom.myvar:color3 }}
If you are using an indexed array set via PHP such as:
$myothervar = array ();
$myothervar[] = 'red';
$myothervar[] = 'green';
$myothervar[] = 'blue';
$logichop->set_data( 'myothervar', $myothervar );
You could use the following Logic Tags to display the values:
{{ var: Custom.myothervar:0 }}
{{ var: Custom.myothervar:1 }}
{{ var: Custom.myothervar:2 }}
Currently with Logic Tags there’s not a way to iterate through the data as you would with a for or foreach loop. However you can use PHP to get the value and then iterate through it, such as:
$colors = $logichop->get_data('Custom.myvar', false);
foreach ( $colors as $color ) {
echo $color;
}
I hope that’s helpful – Please let us know if you have any other questions!
-
This reply was modified 6 years, 2 months ago by
Logic Hop.
Hi,
This is very helpful.
If I understand correctly, it is enough to implode the values in PHP and use a single string as the value for the logic tag variable, and when displaying that in the Gutenberg block to just use it like any other variable with a scalar value. This would be enough for what I need currently to accomplish.
Thank you so much!
Iulia
Thanks Lulia! Yes, I believe that will work as you’ve described. The Logic Hop Custom Object should be able to handle the values that way and be subsequently displayed with a Logic Tag.
Please let us know if you have any other questions.