This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Sergi Bosch
Posted Nov 14 - Read on Facebook

Using a loop, I've added some layers. However, I can't target those layers. Can anyone explain how I can acces layer1...3? Here's the code:

names = ["Mary", "Steve", "Anne"]

for i in [0...3]
rows = new Layer
html: names[i]
y: 45 * i
height: 44
name: "layer" + (i+1)

####not able to hit layer3, why?####
layer3.style =
background: "blue"

5 Comments

Neil Everette

You need to add your row layer to an array I think...

names = ["Mary", "Steve", "Anne"]
rowsArray =[]

for i in [0...3]
rows = new Layer
html: names[i]
y: 45 * i
height: 44
name: "layer" + (i+1)

rowsArray.push(rows)

rowsArray[0].style=
background:"blue"

Brian Williams

Either store references to them in an array or make them the child of something (which I would do for a collection of anything btw just to make transforming and grouping them easier).

https://pastebin.com/MfprKPKj

Maximilian Bredow

Otherwise: i imagine you could expand the array to make it an array of objects and map e.g. “blue” to “Mary” and “red” to “Steve”. I did this in a JSON file in my prototype. Feel free to have a look, perhaps it can help you: https://framer.cloud/iXJbS

Sergi Bosch

thanks for your replies, gentleman. i'm enjoying trying these different options.

Joni El

Hi Sergi, i'd add a parentLayer and target their children with parentLayer.children[1,2,3]

Read the entire post on Facebook