Used to get an attribute by its name from the current
snippet element. There are several means to getting
attributes:
// Get a Box for the attribute:
val myAttr = S.currentAttr("test") openOr "Not found"
// Get an attribute or return a default value:
val myAttr = S.currentAttr("name", "Fred")
// Apply a transform function on the attribute value, or return an Empty:
val pageSize = S.currentAttr("count", _.toInt) openOr 20
// There are also prefixed versions:
val prefixedAttr = S.currentAttr("prefix", "name") openOr "Not found"
Note that this uses the data held in S.currentAttrs, which means that
it will only find attributes from the current snippet element.
For example, given the snippets:
Used to get an attribute by its name from the current snippet element. There are several means to getting attributes:
// Get a Box for the attribute: val myAttr = S.currentAttr("test") openOr "Not found" // Get an attribute or return a default value: val myAttr = S.currentAttr("name", "Fred") // Apply a transform function on the attribute value, or return an Empty: val pageSize = S.currentAttr("count", _.toInt) openOr 20 // There are also prefixed versions: val prefixedAttr = S.currentAttr("prefix", "name") openOr "Not found"Note that this uses the data held in S.currentAttrs, which means that it will only find attributes from the current snippet element. For example, given the snippets:
Calling
S.currentAttr("foo")from snippetB will returnEmpty.