Tinderbox Forum

Exporting set data as links to notes

I’m trying to export a website from a Tinderbox file. Key notes are exported as single pages, and each note/page has a number of “tags” associated via the $Tags set data. I would like the “tag” values exported on each page to be hyperlinks to agents that are exported as pages listing all other notes/pages with that tag. In other words, if I click on a tag name on a page, I am taken to a new page that contains a list of all notes with that tag.

I have tried to follow the instructions on this page but I think I need a bit more help.

Here’s the rule code I’m working with:

$TagExporter = format($Tags, "", "^linkTo(",")^;","");
$TagFormatter = format($TagExporter,"<ul>\n","\t<li>","</li>\n","</ul>\n");

Here’s the result on the exported page:

Tags: * ^linkTo(tagA)^

i.e…, I’m not getting a hyperlinked word and it’s not linking to the intended note.

Here’s the folder structure of my file:

    tagA (agent collecting notes containing tagA)

So I think my question is: how do I get the linkTo command in the above rule to point to these notes in the “Tags” container?

Yikes. First, I’ve just fixed all the broken export mark-up in the page you referenced. Done!

oh right, I should have let you know about that. I was using the TBX file itself as the reference for the most part and forgot about the errors on the HTML.

Can you post your template that (I assume) uses $TagExporter and $TagFormatter. Or, it might be easier to upload a small TBX with your test data (above) in it. That will give us a common reference and can (may be!) fixed in the same context. HTH

Here we go: zkn html export test 2.tbx (117.8 KB)

1 Like

OK, I think the issue is you are using ^value()^ to export $TagExporter data but the latter exports a literal string - i.e. the export code in the $TagExporter value string is not evaluated for export code.

I’m a bit busy this evening, but the route I would try next is to add an ^action()^ (perhaps at the head of the export template) to generate the desired HTML output in full as a string and put that in an attribute (or var() variable) and then use ^value()^ to write the competed HTML code where you currently use ^value($TagFormatter)^.

I’ll try and check back in a bit if I get a chance.

Thanks Dr. Mark! I’ll give it a go. There’s no rush on this, it’s my winter break project over the next few weeks.

I’m guessing that when I wrote the cited article - some while back - the embedded ^linkTo^ code was being evaluated. Another angle might be to use ^include()^—see bottom of article—to include the source evaluated via a template.

So with some help from Mark B via email, I got this to work:

^action($TagFormatter=""; $Tags.each(x){$TagFormatter=$TagFormatter + '<a href="../Tags/ ' + x + '.html">' + x + "</a> | ";} )^

However, this hard-coded the path to the tagA.html file (and etc.) and I didn’t want to do that, as my notes will be in many levels of hierarchy. i.e., sometimes it will be ../../../Tags/tagA.html

So I tried this next:

^action($TagFormatter=""; $Tags.each(x){$TagFormatter=$TagFormatter + '<a href="' + find($Name==x) + '.html">' + x + "</a> | ";} )^

This almost worked, but it doesn’t give me the relative path I need for HTML. i.e., it gave me Tags/tagA.html instead of ../Tags/tagA.html.

So then I tried this:

^action($TagFormatter=""; $Tags.each(x){$TagFormatter=$TagFormatter + '<a href="' + ^root^ + x + '.html">' + x + "</a> | ";} )^

But this didn’t compute–it doesn’t seem like export code is expected in there.

This path business is something I can see being crucial to my project, so I’m eager to learn how to think about paths and how they can be computed within values or other export codes.

I’ve raised this issue in the back-stage. The faces of the problem, is that ^value()^ isn’t export-evaluated for ^code^, and there is no export operator to do so. At the same time, though Action code has a list evaluator (.each(){}), Export code has no such equivalent. Yet your use case, which is not unreasonable, needs to iterate a list (needs action code) that includes export code (which can’t then be evaluated).

I’ve made a feature request/suggestion that ^value()^ behaviour be changed so as to evaluate any Export code in the called value. I don’t see a case where that change would break something and it is it simpler than adding a list iterator operator to Export code.

Thanks Mark. I tend to run into these issues where I’m not sure whether I’m making a feature request or just unsure about which existing feature to use. Thanks for helping me work through it.

1 Like

In this case, you know what the URL of the Tags container is, so you can just hard-code that absolute URL in the export.

If that’s too inelegant, you could use $URL(/path/to/tag/container), though that seems a bit weird.

A reasonable simulation of ^root^ might be built. For example, indented(this,"…/").