Support

Account

Home Forums Add-ons Flexible Content Field Echo nothing if value is X Reply To: Echo nothing if value is X

  • You modification is causing the error, it should be (note the double ==)

    
    if (get_field('jumbotron_horizontal_alignment') == 'Centre') {
              echo 'd-flex text-center justify-content-center';
            }
    

    I’m not sure, did you get it working. In my original reply I was just saying that you need to use get_field() instead of the_field() and add conditional blocks of code. The exact way these are added will depend on what you want to achieve, but given what you supplied in the op the best I could do was a simple example.

    Looking at this

    
    <div class="col-md-12 cxt-title <?php
                                        // if "centre" radio selected, use relevant bootstrap 4 classes
                                        if( get_sub_field('jumbotron_horizontal_alignment') == 'Centre' ):
                                        	echo 'd-flex text-center justify-content-center';
                                        elseif( get_sub_field('jumbotron_horizontal_alignment') == 'Left' ):
                                          echo '';
                                        endif;
                                        ?>">
    

    it does appear the you have the basic idea. You can probably clean it up a bit and make it easier to read by getting the sub field just once and then using that value in your if statements

    
    $halign = get_sub_field(jumbotron_horizontal_alignment);
    if ($halign == 'left') { .....