Export code to query a container for the $Names.icontains...then display the links to the notes in Preview?

I am not sure if this is possible, but I thought I would ask since I am exploring “other uses” of export code.

Here is the scenario: I have a note (Note1) that lives in a flat container with many other notes/siblings.

Is there a way for me to use export code in the text of Note1 to write export code to query the names of the siblings for $Name.icontains(“list”) and show me links to these notes that I can view in preview?

I realize I could write an agent to do this (the right way) but I am just seeing if this is possible using export code.

Thanks
Tom

1 Like

Sure. Here’s one way:

  1. Write a function listNotes() that returns a list of all siblings whose names contain the word “list”.

  2. In the note, export ^value(listNotes())

2 Likes

The last gets you only so far, as it tells you the titles of those notes but doesn’t create the links you desire in preview mode. Well, unless you guess that the function not only needs to find the matches but use generate appropriate ^linkTo()^ code for each match.

Her, use of non-exported preview bites. Export code was written in the expectations of exporting out of Tinderbox at which point the data needed for links would be known. so in this case an agent would be easy as a preview of the agent could use ^childLinks^ to give preview-mode links to each agent child (i.e. matching items. But in your chosen method you need to both find the desired target and make an (HTML) link for each one for preview use. It’s not that it can’t be done, but from the perspective of someone who ‘just’ wants a preview, it involves a little work.

The above suggestion of using a function makes much sense all the lines of action/export code needed to make the HTML don’t have to be in the preview template.

Aside, and noting this as more a feature idea than a suggestion (as I’ve no personal need for this), might it be worth considering a ^listLinks()^ operator akin to the likes of ^childLinks^. The difference would be an extra, and first, argument that is a find(query). The code than takes each ad hoc query-matched item and makes a link with the same 4 optional link customisations as seen in existing link-list making export codes. It’s a long time since export code has had (or needed) a new operator but the above ‘problem’ points to such a possibility.

1 Like

@TomD, take a look at this:

TBX L - Preview Note Navigation.tbx (173.9 KB)

It is a hack, but works.

Click on Note and show in preview
Change the terms you want to search on in MyList on Note
Create Notes with the terms in the names that you want to show in preview

Remember: TBX needs to have previously explored “preview” a destination you. You must have previewed the destination note at least once for the linking to work in Preview. I can explain more later, have to run.

Take a look in the action() in the HTML template.

1 Like

Note the latter also creates an in-doc basic link, which was not asked for. No big deal, in this code in template ‘HTML page’ ^action()^ partsimply comment out the line linkTo(this,x);`:

^action(
var:list vTerm=$MyList;
var:string vNotes;
var:list vList;
vTerm.each(x){
   vList+=collect_if(all,$Name.icontains(x),$Name);
};
vList.each(x){
   vNotes+='<p><a href="'+x+'.html">'+x+'</a></p>';
	linkTo(this,x);
};
)^

On testing that latter doesn’t actually make any links, but if it did, it wouldn’t be needed in the OP’s case. FWIW, were the links required, the working syntax is:

linkTo(x);

See linkTo(scope[, linkTypeStr]) for syntax.

A more direcxt fix is this as the Preiew 9or other named tepmlate applied to the note:

^action(
var:list vList = collect_if(siblings,$Name.icontains("list"),$Name);
var:string vNotes;
vList.each(aNote){
   vNotes+='<li>'+exportedString(aNote,"link-item")+'</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>
<ul>
^value(vNotes)^
</ul>
</body>
</html>

Plus the called template “links-item”, whose code is:

^linkTo(this, ^title^)^

1 Like

Sorry, did not intend to include the linkTo, that was for something else I was playing with.

1 Like