Tinderbox v9 Icon

attribute("attributeName")["key"]


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Altered: 

 Function   [other Function type actions]

 Document   [operators of similar scope]

 Document configuration   [other Document configuration operators]

 9.0.0

 


attribute("attributeName")["key"]

An operator that, for the specified attribute attributeName, returns a Dictionary of key values that describe that attribute. Current keys include (names are all-lowercase and case-sensitive):

attribute("attributeName").keys

Keys are returned in the order listed above, and not in alphabetical order—as might be intuited. Being a Dictionary operator, it is possible to retrieve all the above as a list of key:value pairs. Note that any attribute name (any valid name) must be supplied as first argument:

$MyList = attribute("Width").keys; 

returns the entire contents of the Dictionary key:value pairs for the attribute Width.

The attribute name can be a variable , so a more useful method is to iterate the list of keys:


var:list vKeys;
var:string vOutput;
vKeys = attribute(anAttribute).keys;
vKeys.each(aKey){
	vOutput += aKey + ": " + attribute(anAttribute)[aKey] + "\n";
};
$Text = vOutput;

By combining with document(), it is possible to make a stamp that creates a listing of all user attributes in the current document, iterate each one, report only keys with a value and place the resulting data in the $Text of the stamped note. the stamp code is;


var:list vKeys;
var:string vOutput;
var:list vAttributes = document["user-attributes"];
vOutput += "TBX filename " + document[name] + "\n";
vOutput += "Number of  user attributes: " + vAttributes.count + "\n--------------------\n";
vAttributes.each(anAttribute){
	vOutput += "--------------------\n" + anAttribute + "\n" +"----------\n";
	vKeys = attribute(anAttribute).keys;
	vKeys.each(aKey){
		if(attribute(anAttribute)[aKey] != "" & aKey != "category"){
			vOutput += aKey + ": " + attribute(anAttribute)[aKey] + "\n";
		};
	};
};
$Text = vOutput;

Key values

If any key is not set, e.g. there are no 'suggested' values, then an empty string is returned for that key.

All keys return as string, but the most appropriate attribute type is shown as the recipient of the data:

$MyList = attribute("Width")["default"] 

$MyList = attribute("Width")["suggested"] 

$MyString = attribute("Width")["category"] 

$MyString = attribute("Width")["type"] 

$MyString = attribute("Width")["description"] 

Note that when using literal (i.e. actual) attribute name or keys it is recommended the word(s) are quote enclosed as above. If using variables, as in the earlier code examples, quotes are not used as this aids the Tinderbox parser detecting literal vs. variable usage..

Editing key values

Some keys can be modified via action code. Actions may modify (only) the default or suggested values of an attribute:

attribute("attributeName")["suggested"]="value 1; value 2"; 

sets two values for the attribute's suggested values list. Likewise a default value can be set:

attribute("attributeName")["default"]="value 1"; 

Thus, for instance, action code might find the discrete values for an attributes (use values() or collect(), etc.) and use that list to set/update the attributes suggested values (i.e. the suggested key value).



A Tinderbox Reference File : Actions & Rules : Operators : Full Operator List : attribute("attributeName")["key"]