Exporting all attributes for a note

I am probably missing (again) the documentation is on this, so apologies in advance.
I have a grading system with quite a number of different prototypes, each with a different set of attributes. Some are boolean, some strings. What I would like to do is have a generic HTML Item template that iterates through whatever attributes are there for a note and prints them, rather than have to go through each and create export templates for each prototype (using ^value($SomeAttribute)…)

Is this possible?

Every attribute is defined for every note; if you exported every attribute, you’d have a list of hundreds of attributes for each note.

What I think you want to do is export every key attribute for a note. You can do this, but I’m not sure it’s a great idea.

If you have one or more prototypes for each of the sorts of things you’re exporting, and each prototype has its own template, it’s really easy to export ^value($SomeAttribute) for each thing you want to export. If you want to export more stuff, or change the way its formatted, everything is in the template. If you use the same template for everything, changes are harder.

Still, this will do what you want. Spaces and line breaks added for clarity; take them out before trying this.

^action($MyString=“”;$KeyAttributes.each(x){ $MyString=MyString+“<p>”+x+“:”+eval(“$”+x)+“</p>”})
^value($MyString)

What we do here is build an HTML string piecewise in $MyString, and then export $MyString. It gets the job done, but if (for example) you wanted to switch to tabular markup, it’d be a bit of a nuisance.

All notes ‘have’ all attributes, even if the value is the default. So perhaps you need to refine your definition.

Or, do you mean all a note’s key attributes ? IOW, those attributes displayed at the top of a note’s text pane when selected. The latter is stored in (or inherited to) $KeyAttributes. If the latter, perhaps something like:

^action(
	if($KeyAttributes!=""){
		$MyExportString=;
		$KeyAttributes.each(X){
			$MyExportString=$MyExportString+"<li>"+X+": "+eval("$"+X)+"</li>\n"
		};
	}
)^<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8">
	<title>^title^</title>
</head>
<body>
<h1>^title^</h1>
^text^
^if($KeyAttributes!="")^<ul>
	^value($MyExportString)^
</ul>^action($MyExportString=;)^^endIf^
</body>
</html>

I get output like:

Some test text.

  • MyNumber: 0
  • MyList: ant;bee
  • MyDate: 10/05/2017, 20:26

Edit: looks like I was beaten to the post, but encouragingly the main part of the code is the same - iterating a list and saving it into a string.

1 Like

If a single template suffices (with a nod to the suggestions above), you can create a “basic” prototype – say protoBase, which all other prototypes inherit, and you can give protoBase your generic template. It will then get inherited by all other prototypes that descend from protoBase, until you override $HTMLexportTemplate for one of the descendant prototypes.

One can set up template descendants, also, but it’s a bit more complicated, and I don’t think it is helpful here.

Thanks all for the help! I should have been more specific - I was looking to export only KeyAttributes.

1 Like

Thanks. Should you find yourself wanting all (used) values for a specific attribute, look at values(). Or, if you need that info but not for all notes, use collect().

Exporting these value lists to HTML is possible by using the same ^action()^ based method as above.