Home Forums Add-ons Flexible Content Field Show Empty Fields Reply To: Show Empty Fields

  • just to understand:

    • you had a flexible field with 15 layouts.
    • at page/article/cp you show that flexible field.
    • you/user can now select one or more of this flexible fields.

    and all that you wish is, when you didnt select/add the neck: you dont want to show neck?

    that is what flexible field normally does. (add optional content-blocks, and show them only if needed. with that you can have required fields like a keyvisual a with title, but only when you add keyvisual-block)

    what it does not do is: to look if a layout is already choosen 1 or more times, and if not display a alternate content.
    if you really need that you need to set a variable inside the get_row_layout loop. also you had to put the values into a variable first. after all layout you check each variable and check if it is filled or not & set alternates

    try if you can adapt this code

    //define variables 
    $head= '';
    $shoulder ='';
    $neck ='';
    //check for layouts and the values inside
    if( have_rows('attach_files_multiple') ): while ( have_rows('attach_files_multiple') ) : the_row(); 
    if( get_row_layout() == 'neck' ) : 
    $neck .= 'all about neck';
    if( get_row_layout() == 'shoulder' ) : 
    $shoulder .= 'all about shoulder';
    if( get_row_layout() == 'head' ) : 
    $head .= 'all about head';
    endwhile; endif;
    //check for filled values and build layout or the alternates
    if ($head) {
    echo $head;
    } else {
    echo 'no head was chosen ';
    if ($shoulder) {
    echo $shoulder;
    } else {
    echo 'no shoulder was chosen ';
    if ($neck) {
    echo $neck;
    } else {
    echo 'no neck was chosen ';

    why do you work with flexible fields when you replace anyway everything not filled with a default value?