Using wrapTpl in cbGetFieldContent

Hello.
I’d like to create carousel with cbGetFieldContent, and I use wrapTpl option for it, but the snippet ignores this option and uses only the tpl chunk for every field. Could you help me to resolve this issue?
Here is my snippet call:

[[!cbGetFieldContent? 
       &field=`19` 
       &wrapTpl=`tpl.CarouselWrapper`
]]

here is the tpl.CarouselWrapper source:

<div id="carousel" class="carousel slide mb-5" data-bs-interval="999999" data-bs-ride="carousel">
    <div class="carousel-indicators">
        <button type="button" data-bs-target="#carousel[[+id]]" data-bs-slide-to="0" class="active" aria-current="true" data-bs-ride="false"></button>
        [[cbGetFieldContent? 
            &resource=`[[+id]]` 
            &field=`19` 
            &limit=`0` 
            &tpl=`tpl.carouselIndicator`
            &params=`{"carouselid":"carousel[[+id]]"}`
        ]]
    </div>
    <div class="carousel-inner">
        [[+rows]]

        <button class="carousel-control-prev" type="button" data-bs-target="#carousel[[+id]]" data-bs-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Previous</span>
        </button>
        <button class="carousel-control-next" type="button" data-bs-target="#carousel[[+id]]" data-bs-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Next</span>
        </button>
    </div>
</div>

Another question is there any way to create carousel indicators without call the cbGetFieldContent snippet again inside the wrapTpl chunk?
Thank you.

Hm, assuming field 19 is a repeater, I don’t see any reason that wouldn’t work. Is that your full snippet call or is there perhaps more you didn’t post for simplicity? Because you mention the &tpl property but that’s not there in what you posted. Sometimes an error elsewhere in the snippet call can prevent the parser from getting to other properties.

Have you triple checked the wrapTpl chunk name to make sure that is correct?

Also, there’s no need to call cbGetFieldContent uncached.

If all the information you need for the indicators can be parsed from the [[+rows]] output, you could use a custom snippet that parses that DOM as an output filter. Other than that, no, the current templating doesn’t doesn’t let you iterate over the rows twice with different templates.

Thank you for you answer.
I’ve created the video with my issue. Could you look it ?
Thanks.
https://www.awesomescreenshot.com/video/24040221

Also I can’t use idx placeholder in the cbGetFieldContent snippet, when I call it inside the pdoResources, because it rewrite idx value. Is there another way to get counts of items?
Thank you.

That video link doesn’t seem to work :frowning:

This ^ is the most reliable approach to deal with parsing a repeater twice, you can get your idx through that custom snippet too. Depending on which idx you mean (there’s a number of different ones) they may be different when called in cbGetFieldContent vs the regular resource output.

1 Like

sorry, forgot the access key in the url
here is the correct link:
https://www.awesomescreenshot.com/video/24040221?key=88fa7d4ce1f19d72ee1dd90a6db84f4a

Ah, I see, you’re iterating over individual image fields.

The &wrapTpl property only works for repeating fields, like the repeater, gallery, or files input types. It sets the wrapper which that one specific field, with multiple values, will use. The image input only has a single value, so no wrapper template, and no support for &wrapTpl.

In your case, I think you can simply put your wrapTpl in the template itself and call cbGetFieldContent twice:

<div id="carousel" class="carousel slide mb-5" data-bs-interval="999999" data-bs-ride="carousel">
    <div class="carousel-indicators">
        <button type="button" data-bs-target="#carousel[[+id]]" data-bs-slide-to="0" class="active" aria-current="true" data-bs-ride="false"></button>
        [[cbGetFieldContent? 
            &resource=`[[+id]]` 
            &field=`19` 
            &limit=`0` 
            &tpl=`tpl.carouselIndicator`
            &params=`{"carouselid":"carousel[[+id]]"}`
        ]]
    </div>
    <div class="carousel-inner">
        [[cbGetFieldContent? 
            &resource=`[[+id]]` 
            &field=`19` 
            &limit=`0` 
            &tpl=`tpl.carouselContent` <-- change this
            &params=`{"carouselid":"carousel[[+id]]"}`
        ]]

        <button class="carousel-control-prev" type="button" data-bs-target="#carousel[[+id]]" data-bs-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Previous</span>
        </button>
        <button class="carousel-control-next" type="button" data-bs-target="#carousel[[+id]]" data-bs-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Next</span>
        </button>
    </div>
</div>
1 Like