https://twill.io logo
Hi! Team, is it possible to use one repeater but w...
# ❓questions
v
Hi! Team, is it possible to use one repeater but with dynamic data? Let's say we have a repeater with select, but this select must take options from dynamic array, which we can provide? There's second question, how we can provide dynamic data to repeater? I tried to use ViewComposer, but I always got the same data in all repeaters... Reason is: we try to use the same repeater in two blocks but settings of repeaters depend on block. Seems this task is mind blowing 🙂
i
Hi @VadimG the repeater doesn't have context about which block it is in, so you won't be able to dynamically change it depending on the block type. You can use 2 repeaters that include the same blade view with different data to avoid the code duplication.
v
@ifox theoretically, I can pass the context by ViewComposer, there's another problem: repeater is building only one time, then it used in all view 🙂 Checked with passing random int to view with view composer)
Maybe you can advice any workarouds? I can use block classes to store data for block (parent), and in TwillServiceProvider I can overwrite methods when ViewComposer works, but I have no idea why if I add some dynamic value in view - there's only one stored value
i
Could you share some code to reproduce what you're trying to do? The best workaround is to use 2 different repeaters as it would be much simpler in my opinion.
v
But we have more than 2:) 10-15 same repeaters but with different data
In TwillServiceProvider I trying to check idea - add random int $var to repeater
And dump the variable $var in repeater view
I think I don't fully understand how ViewComposer works, but when i dump $var - it's not set
@ifox So I just trying to find a way to pass any random data to view though view composer, but maybe I don't understand how view is built, idk
@ifox @Harings Rob Hi guys! Sorry for ping 🙏 , but maybe this problem has solution? When I would like to use 1 repeater but with 20 blocks with different data? Thank you!
Okay, just have to postpone it
i
Hey @VadimG sorry there's no immediate solution to this problem. Please share the use case so we can share a potential alternative
v
Hi, @ifox , np, thank you for the reply! I have 1 repeater with select inputs which must be used on all existing blocks, but inputs variations of the repeater depend on block, we have to duplicate repeater and pass different data in, but repeater is the same. Trying to find a workaround
2 Views