• Resolved Iulia Cazan

    (@iulia-cazan)


    Hello,
    First of all, I would like to say that this plugin is amazing, I like a lot the Gutenberg blocks feature.

    I was looking through the documentation and could not find any example or description about how to display the data logic tags of an array type.

    In my case, I am trying to use a custom object data that stores an array let’s say like Custom.myvar.colors that is actually something like `[colors] => Array
    (
    [color1] => red
    [color2] => green
    [color3] => blue
    )`.
    How do I iterate through these when trying to display the variable? I tried with {{ var: Custom.myvar.colors }} and it just displays Array.

    Thank you!
    Iulia

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Logic Hop

    (@logichop)

    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 4 years, 8 months ago by Logic Hop.
    Thread Starter Iulia Cazan

    (@iulia-cazan)

    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

    Plugin Author Logic Hop

    (@logichop)

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Data Logic Tags’ is closed to new replies.