Tinderbox Forum

Conditional display of attributes

I seem to remember that this has been discussed before, but I can’t locate the corresponding topic – apols.

Here’s the scenario:
Some of my prototypes have a good number of attributes displayed. However, not all of these are relevant for all notes created for that prototype subsequently. For example, notes on films will typically have a $TimeCode and be linked to a video file ($vURL), whereas for notes on books or articles neither of these make sense and they tend to get in the way if they are displayed.
How would I hide irrelevant or unused attributes if these are shown in the prototype? Or would it be easier to start with an empty attributes table and choose which ones to display? I presume there are at least the following two steps involved:

  1. Formulate the condition for showing/hiding the attribute,
  2. Tell Tinderbox which attributes to show/hide.

Any help would be much appreciated.

Would it make sense to have separate prototypes for Books and for Films? Perhaps each inheriting from a common ancestor, Sources, but differing in displayed attributes?

Great suggestion, Mark, and so simple :wink: . The more general question remains, however: is there a way of formulating conditions for the display of attributes?

In principle, an agent (or a rule or edict) could modify $DisplayedAttributes. For example:

if($Director!="") { $DisplayedAttributes += "Director;Producer;";}

This would add extra displayed attributes if the source has a director.

It’s worth noting it would also break inheritance from any prototype in use. That doesn’t invalidate the code above, but beware if using it in context with prototype.

There is a further issue. Displayed Attributes’s predecessor $KeyAttributes was a Set, but $DisplayedAttributes is a List so the above code has the consequence that every time a rule or edict runs the two attributes are re-added. To avoid that use:

if($Director!=""){
    if(!$DisplayedAttributes.contains("Director")){
        $DisplayedAttributes += "Director;Producer;";
    }
}

You could also switch out $Prototypes via a Rule/Agent depending on your specific usage or point within your project; the two Prototypes can be identical except for their $DisplayedAttributes value.

I sometimes like to know the status of all Attributes in a set of Notes - even the information that a field is blank can be critically important. Swapping between 2 Prototypes will allow concurrent use of “long Attribute list” vs. “essential Attributes list” views, for example.

1 Like