Tinderbox Forum

Populating many notes with new $Text

I am fiddling with exporting for the first time (!) and realizing that I want to replace $Text for notes under a certain prototype. I’ve chosen to do this with a stamp as it’s worked well before, but this time I am using action code that contains " marks and so the stamp is stopping the $Text replace when it finds those "s.

The stamp I’m trying is:
$Text="Participant: ^value($PID)^, Data Item: ^value($DID)^ ^action($MyList=$Tags;$MyList=$MyList.format("<ul>","<li>","</li>","</ul>");)^^value($MyList)^"

And it breaks at the first " in $MyList.format.

First, is there a better way?
Second, if this is an okay way, how to escape those quotes? (I tried \" but it didn’t work.)

Use single (straight) quotes:

$Text='Participant: ^value($PID)^, Data Item: ^value($DID)^ ^action($MyList=$Tags;$MyList=$MyList.format("<ul>","<li>","</li>","</ul>");)^^value($MyList)^';

Although the general convention is to use double (straight) quotes to delimit strings, you can indeed use either. If, as here, you use both types, ensure they are nested properly. Here all the double quotes are inside the string formed by the outer set of single quotes.

This is important as single/double straight quotes cannot be escaped using a backslash.

Having fixed the quote issue, i’m unclear why you need to stamp this into the $Text of notes. Why not make a template:

<!DOCTYPE html>
	<meta http-equiv="content-type" content="text/html; charset=utf-8">
<p>Participant: ^value($PID)^, Data Item: ^value($DID)^</p> 

As seen here: Export-without-text.tbx (91.4 KB)

Note how you can still use the $Text of the note for actual text as the template doesn’t use the $text in the export. Both Set and List type attributes ‘lists’—i.e. multi-value—so you can apply the 4-input list formatting as shown above and in the demo file.

1 Like

Just learning about templates that’s why, but you just blew my mind on a couple different levels. :exploding_head:


Great! The pay-off for ‘some assembly required’ rather than a black-box feature for export is you can do some wonderfully rich things, including making multiple different outputs using the same data (whether using different formats or different choices from the source data).

Also, if you have some facility with HTML it can be useful sometimes to make an HTML (or XML, markdown, etc.) page that looks like the desired result to help you figure what source info you need and where it needs to go in the template.

1 Like

Yes, my first stop was .md and now I’m tinkering with XML!

1 Like