Home › Forums › Add-ons › Flexible Content Field › Get content of layout as an array › Reply To: Get content of layout as an array
No, there isn’t a better way if what you want is have an array with the data. Or maybe there isn’t, I might do it differently in order to remove an extensive if/elseif/elseif
based on the code you provided
// get the entire flex field
$layouts = get_field('page_layout');
if ($layouts) {
foreach ($layouts as $layout_data) {
$layout_name = str_replace('_', '-', $layout_data['acf_fc_layout']);
$template = locate_template('component-templates/'.$layout_name.'-block.php', false, false);
if ($template) {
// why am I doing this?
// if locate_template returns false, include(false) will throw an error
include($template);
}
} // end foreach layout
} // end if layouts
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.