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
?>
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.