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

What is Framer? Join the Community
Return to index
Mark Graham Dunn
Posted Jan 21 - Read on Facebook

hi all, is it possible to traverse a list of subgroups inside a parent group to get to a layer name
example
- Group A
-- Subgroup 1A
-- actionBtn
-- Subgroup 2A
-- actionBtn
-- Subgroup 3A
-- actionBtn

6 Comments

Mark Graham Dunn

sorry, figured this noobish question out.

Joshua Tucker

You can do this in a number of different ways:

Using print, for example, you can print the subLayers of Quotes (which is the artboard imported from Sketch in my example) and it will show its subLayers by doing:

print [group_name].subLayers

This will print Quotes' (the artboard) sublayers.

But it sounds like you want the "actionBtn" layers to come up, right? Those are nested inside the subLayers of the highest group.

For that, you would want to create a for loop to loop through each subgroup and print its sublayer. That's shown in my included picture at the top, but here's the write-out:

for [any variable you'd like to use] in Quotes.subLayers
print [the variable above].subLayers

You can always store these to another variable if you wish to transfer them over to something else.

If you check out the docs page on the Framer site (http://framerjs.com/docs), some helpful snippets to look at that might help also include:

- layer.subLayers
- layer.subLayersByName

Mark Graham Dunn

whoaha, thanks Joshua. That's what i was looking for.
Really need to get acquainted with the docs and examples.

Joshua Tucker

Mark Graham Dunn For sure, man! I hope that works out for what you're working on. Share it with us if you're able to in the future :). We always love seeing cool stuff. Also, the Docs available are a great start, and as always, you're welcome to post here. No question is too dumb. We are all here to learn!

Amy Casillas

Joshua, in your example you use:

myLayers = Framer.Importer.load "..." Framer.Shortcuts.initialize(myLayers)

How is this different from:

newLayers = Framer.Importer.load "imported/someSketchFile"

for layerGroupName of newLayers
window[layerGroupName] = newLayers[layerGroupName]

? I've never seen the Shortcuts statement before.

Joshua Tucker

Amy Casillas It's a library created by Facebook that adds a number of shortcut features to Framer (available here: https://github.com/facebook/shortcuts-for-framer). One of its features is being able to call the groups by their actual name, not newLayers["layer_name"]. Really the only difference, in this instance, is not having to do a for-loop as you described above. I can just initialize as you provided at the top of your comment and its done.

I could start just doing the for-loop, but I have just gotten so used to adding the library.js file. I don't use the Facebook Shortcuts for much else than that. LOL.

Read the entire post on Facebook