Support

Account

Home Forums ACF PRO Get image repeater URL into JS image path Reply To: Get image repeater URL into JS image path

  • You do this the same way that you do it with anything else that uses a repeater except that you’re outputting JS instead of HTML. The main difference here is that the JS for this needs to be inline in your template as this cannot be done in a separate JS file.

    
    <?php 
      if (have_rows('repeater')) {
        ?>
          <script>
            jQuery(document).ready(function($) {
              $("#example, body").vegas({
                sildes: [
                  <?php 
                    // I'm using an array here and implode later
                    // to make it easy to exclude a comma after the list item
                    $images = array();
                    while (have_rows('repeater')) {
                      the_row();
                      $images[] = '{src: "'.get_sub_field('image').'"}';
                    } // end while have_rows
                    echo implode(',', $images);
                  ?>
                ]
              });
            });
          </script>
        <?php 
      } // end if have_rows
    ?>