Home › Forums › Add-ons › Flexible Content Field › Need help for correct markup for nested flexible content field › Reply To: Need help for correct markup for nested flexible content field
this is a markup that works for me
(that has the content-blocks inside sub-flexible fields.
flexible field my_customcontent_width with layouts:
my_customcontent_full and my_customcontent_half_half
flexible field my_customcontent inside my_customcontent_full
with layout text_block
flexible field my_customcontent_lefthalf inside my_customcontent_half_half
with layout text_block
flexible field my_customcontent_righthalf inside my_customcontent_half_half
with layout text_block
)
<?
if( have_rows('my_customcontent_width')):
while ( have_rows('my_customcontent_width') ) : the_row();
if( get_row_layout() == 'my_customcontent_full' ){
if( have_rows('my_customcontent') ):
echo '<div class="full">';
// loop through the rows of data
while ( have_rows('my_customcontent') ) : the_row();
//text block start
if( get_row_layout() == 'text_block' ){
$text = get_sub_field('my_text');
echo $text;
}
//text block end
endwhile;
echo '</div>';
endif;
}
if( get_row_layout() == 'my_customcontent_half_half' ){
echo '<div class="lefthalf">';
while ( have_rows('my_customcontent_lefthalf') ) : the_row();
//text block start
if( get_row_layout() == 'text_block' ){
$text = get_sub_field('my_text');
echo $text;
}
//text block end
endwhile;
echo '</div>';
echo '<div class="righthalf">';
while ( have_rows('my_customcontent_righthalf') ) : the_row();
//text block start
if( get_row_layout() == 'text_block' ){
$text = get_sub_field('my_text');
echo $text;
}
//text block end
endwhile;
echo '</div>';
}
endwhile; endif;
?>
but why use a flexible field with just a single layout inside?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.