Skip to content

Instantly share code, notes, and snippets.

@IainIsCreative
Created October 19, 2015 10:03
Show Gist options
  • Save IainIsCreative/741672eea0fb3068c7d2 to your computer and use it in GitHub Desktop.
Save IainIsCreative/741672eea0fb3068c7d2 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
// Nested map example
$nested-map: (
key-1: (
deep-key-1: (
deeper-key: true
),
deep-key-2: true
),
);
// map-fetch function to fetch nested keys
@function map-fetch($map, $keys) {
@each $key in $keys {
$map: map-get($map, $key);
}
@return if($map, true, false);
}
// nested fetch that directly fetches from $nested-map specifically
// $key references the
//
@function nested-fetch($key, $nested-key){
$result: map-fetch($nested-map, $key $nested-key);
@return if($result, $result, 'null');
}
$foo: nested-fetch(key-1, deep-key-1 deeper-key);
// returns null(??)
$bar: nested-fetch(key-1, deep-key-2);
// returns true
$baz: map-fetch($nested-map, key-1 deep-key-1 deeper-key);
.foo:before {
content: '' + $foo + '';
}
.bar:after {
content: '' + $bar + '';
}
.baz:after {
content: '' + $baz + '';
}
.foo:before {
content: "null";
}
.bar:after {
content: "true";
}
.baz:after {
content: "true";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment