<footer id="footer">
<div class="container">
<div class="row double">
<div class="6u">
<div class="row collapse-at-2">
<div data-sly-repeat="${properties.colNum}" data-sly-unwrap>
<div class="6u">
<h3>Accumsan</h3>
<ul class="alt">
<li><a href="#">Nascetur nunc varius</a></li>
<li><a href="#">Vis faucibus sed tempor</a></li>
<li><a href="#">Massa amet lobortis vel</a></li>
<li><a href="#">Nascetur nunc varius</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="6u">
<h2>Aliquam Interdum</h2>
<p>Blandit nunc tempor lobortis nunc non. Mi accumsan. Justo aliquet massa adipiscing cubilia eu accumsan id. Arcu accumsan faucibus vis ultricies adipiscing ornare ut. Mi accumsan justo aliquet.</p>
<ul class="icons">
<li><a href="#" class="icon fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="#" class="icon fa-facebook"><span class="label">Facebook</span></a></li>
<li><a href="#" class="icon fa-instagram"><span class="label">Instagram</span></a></li>
<li><a href="#" class="icon fa-linkedin"><span class="label">LinkedIn</span></a></li>
<li><a href="#" class="icon fa-pinterest"><span class="label">Pinterest</span></a></li>
</ul>
</div>
</div>
<ul class="copyright">
<li>© Untitled. All rights reserved.</li>
</ul>
</div>
</footer>
I am trying to use data-sly-repeat to loop and I have verified that the value of colNum is 2 but still the loop is running only once. In other words, it doesn't loop through irrespective of the value. I also hardcoded the value 3 but it still won't run the loop more than once. Not sure what I am doing wrong here.
Thanks in advance
It seems you have misunderstood how
data-sly-repeat
is intended to be used. You can read their documentation to get clarification.Two things:
data-sly-repeat
repeats the whole element that is marked, whiledata-sly-list
only repeats the content of the element. In your case it seemslist
is more appropriate.. You can eliminate the actualdiv
that you are currently unwrapping.Rather than passing in a number of times to repeat the HTML you pass in a list of things to iterate over. The html is rendered for each item in the list, with the
${item}
variable being used to hold the current item.So, you'll have to write some Java of JS code to turn your
colNum
into a list of that size.For example, using the JS Use API. (see this question for ways to create empty iterable arrays)
And calling it from the HTL. Notice I removed the extraneous
div
and am usingdata-sly-list
to loop over then
length array of empty elements