• Resolved thePixelPixie

    (@yourbusybee)


    Hi there,

    I LOVE your plugin. It’s the perfect addition to the most useful WP plugin ever created.

    I’m just delving into Dynamic Render for the first time today. An issue I’m having is that I need to somehow get an index count of each layout on the page, and here’s why (I’m open to suggestions of better ways to accomplish this): Some of the blocks of content, like carousels, or blocks with modals, require unique targets. So if one of my content editors were to add, say, 2 carousels on a page, each one would need to have a unique (in Bootstrap, for example) ID and data-bs-target. The way I’d been handling this up until now was to have the following at the start:

    <?php while(have_rows('choose_layout_items')) {
       the_row();
       $layout = get_row_layout();
    
       if(!isset($layout_counts[$layout])) {
          $layout_counts[$layout] = 0;
       }
       $layout_counts[$layout]++; ?>

    And then putting this in the classes for each layout:

    layout-<?php echo get_row_index(); ?>

    This allows me to have custom styles for individual blocks that also reference that row index number. Example:

    data-bs-target="Carousel<?php echo get_row_index(); ?>"

    I do know it’s not great form to put <style></style> elements inside the main content area, but with the need for having styles that reference specific layout numbers, it’s what I’ve wound up doing. I’m not sure what another solution might be though. I’m definitely open to suggestions. But I am also hoping there’s a way to get that layout count, while using Dynamic Render.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    I’m glad to hear that you enjoy ACF Extended ??

    In order to retrieve the Flexible Content row index, you can use the native acf function get_row_index() anywhere within the have_rows() loop (See documentation).

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter thePixelPixie

    (@yourbusybee)

    Thanks loads. However, I think maybe I’m missing something here. In the documentation, it shows the following code needed for rendering on the front end:

    if(has_flexible('flexible_content_field_name')): the_flexible('flexible_content_field_name'); endif;

    Do you mean that this works similar to have_rows() and that I could add the get_row_index() inside this statement in the same way?

    (obviously I’m going to give it a shot right now, but I figured someone else might have the same question if they look through this down the road)

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    Absolutely! the_flexible() uses have_rows(): the_row() loop behind the scene, and automatically include() layouts PHP files when needed.

    So any ACF function such as get_row_index() will work in the layouts PHP files.

    I hope this answers your question.

    Have a nice day!

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Dynamic Render – Somehow need an index count’ is closed to new replies.