Support

Account

Home Forums Add-ons Flexible Content Field Write CSS with PHP and Flexible Content Reply To: Write CSS with PHP and Flexible Content

  • I’m sorry if this isn’t answering your question directly, but for things like this, wouldn’t it be simpler to just assign a class to the layout and then style that class appropriately?

    For instance:

    
    <?php if( have_rows('pagebuilder') ): ?>
      <?php while( have_rows('pagebuilder') ): the_row(); ?>
        <?php if( get_row_layout() == 'page_mainteaser' ): ?>
    
        /* Site-Mainteaser */
    
        // I made these attributes multiline to read easier on these forums
        <div id="mainteaser" 
             style="background-image: url('<?php the_sub_field('background'); ?>')"
             class="headline-<?php the_sub_field('color_headline'); ?> 
                    text-<?php the_sub_field('color_text'); ?>" 
        >
          <!-- Layout content here... -->	
        </div>
    
        <?php endif; ?>
      <?php endwhile; ?>
    <?php endif; ?>

    Then in your stylesheet add corresponding styles like:

    .headline-red h1 { color: red }
    .headline-blue h1 { color: blue }
    .headline-green h1 { color: green }
    
    .text-black p { color: black}
    .text-white p { color: white }