Home Forums Add-ons Flexible Content Field Prevent access variable outside get_row_layout()


Prevent access variable outside get_row_layout()

  • Hello, I created variables to get the value of my get_sub_field() inside the get_row_layout() and I have encountered an issue. I can still access the variables even I’m not inside in the get_row_layout() or even outside of the while loop. I just created the variable inside the get_row_layout() but I can still access and output the value. I expected that it will have an error like “unexpected variable”.

    <?php if( have_rows('property_paragraph_flexible_field') ): ?>
        <?php while ( have_rows('property_paragraph_flexible_field') ) : the_row(); ?>
            // Case: Paragraph layout 1
            if( get_row_layout() == 'property_paragraph_flexible_field_layout1' ):
                $m_id = get_sub_field('property_paragraph_flexible_field_layout1_field1');
                $title = get_sub_field('property_paragraph_flexible_field_layout1_field2');
            <?php endif; ?>
            <?php echo $title; ?>
        <?php endwhile; ?>
    <?php endif; ?>
  • PHP does not work like this. The if statement is true so $title is assigned a value. This value is this variable is available anywhere in the same scope of PHP after is is assigned… anywhere in the same file, unless you change the variables value.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.