Forum
Passing variables inside block templates
Hi there
I am trying out blocks. I's superb. But there's one thing I am having a block with brain-wise.
I have a bootstrap image carousel inside one block that has two loops using the same set of data (one displays the images, the other the indicators).
Previously I would have displayed this using perch_custom_content from a layout template and used two templates - one for each loop. But now the carousel is called from a block inside an html file. How do I pass variables from one html template to another? i.e. from the carousel image template to the carousel indicator template?
Am I being a totally numpty?
I'm having trouble visualising the problem. What does your code look like?
Hi Drew
I hadn't actually coded anything! I've worked it out. It was a numpty thing. I've just repeated the repeater id for both list items in the template below.
The question now is if I have a checkbox "carousel_active" allowing images to be turned on and off, how do I get the second loop (for carousel indicators) to count the right number of items. At the moment it skips the item rather than counts through the number of items. i.e. 0,2,3 not 0,1,2 if item 2 is not active. This then breaks the clickable navigation on the indicators.
Hmm. I'm not sure I have an answer for that one.
perch_item_index
gives the index of the item in the set, but doesn't account for any you choose not to display.Ok thanks Drew. I will take out the active function for now. It's not vital.
If I recall Expression Engine has a simple count tag that allows you to iterate through filtered entries without relying on the original array of data returned. Perhaps <perch:count> would be a useful future feature request for other Perchers out there?
We are looking at adding some basic math features to the template engine, but I can't promise anything immediately.
Thanks Drew.