Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
Tinderbox Users >> Exporting from Tinderbox >> Exporting using collect_of, or something like it

Message started by rtalexander on Jan 15th, 2013, 6:44pm

Title: Exporting using collect_of, or something like it
Post by rtalexander on Jan 15th, 2013, 6:44pm


Is there a way, using export code, to export a specific collection of notes? I've have tried the following using exportedString, but with mixed results:

^value(exportedString( collect_if(children,$Prototype=="Task",$Name), SomeTemplate) )^

If I understand the documentation correctly, the first argument must be the name of a note or a designator. I have also tried using find, as follows:

^value( exportedString( find($Prototype=="Task" & $Path==$Path(parent)), SomeTemplate))^

So I guess the more general question is, is there a way, at export time, to specify a set of items (vis-a-vis collect_if) that are to be exported?


Roger Alexander.

Title: Re: Exporting using collect_if, or something like it
Post by Mark Bernstein on Jan 15th, 2013, 7:56pm

I don't remember whether exportedString can accept a group designator, or if it’s limited to a single note.  The latter was my intent when I wrote it!  But it could be generalized without too much pain, I think.

Easy way to test this yourself: replace the complicated "collect" and "find" expressions with a simple list.

First, try the conventional case:

    exportedString(/container/example,template)   <- try this first

Next, a list.

     exportedString(/thing1;/thing2,template)   <- try this next

If you can export a list, then you simply need to build the list with find().  If this doesn't work, email info@eastgate.com and tell us more about what you're doing and why.

Title: Re: Exporting using collect_of, or something like it
Post by Mark Anderson on Jan 16th, 2013, 6:29am

My notes have exportedString() as using single item scope. I'd always thought of this operator as a way of transforming data inside a TBX using export code.  Although using export code directly within action code is now deprecated, this method does so at arms' length as the export code is in a template (or supplied as a parameter). In other words, it was an internal transform powered by export code. That said there's no reason it can't then be used for export as per your method.

Later edit: re-testing in v5.12.0, it appears exportedString is indeed limited to a single item, rather than either a single item or a list. Judging by the preceding post that limitation may get fixed in due course.

Whatever, in v5.9.2+, ^include()^ was improved to support group scope - i.e. more than one item, in list form. I recall the genesis of this was the export template coding for Ted Goranson's blog. The right column of the latter has lots of per month listings made with multiple ^include()^ calls using a list which is (re-)populated immediately before each include : an ^action()^ wrapper around an action code to seed the include's list from a find() or collect_if().

Back to @rtalexander's problem. I'd suggest:

^include($IncludeSet, "SomeUniqueTemplateName")^

Note I've altered your collected attribute from $Name to $Path to help disambiguate info. $Path's longer, but you never actually see the textual values anyway.

As collect_if() by default returns a list of $Path of matched notes, I'd make the include group a Set and not a List type of attribute as a Set will automatically de-dupe the list for you (should dupe matches occur).

Note too that $IncludeSet is reset after the include so we don't get query result data hanging around in the reference. You don't have to even set the list in the template via ^action()^. But why might you do so? Because the method scales, here we list Tasks A, B and C and separate dynamically calculated group includes - all within a single template:

^include($IncludeSet, "SomeUniqueTemplateName")^
^include($IncludeSet, "SomeUniqueTemplateName")^
^include($IncludeSet, "SomeUniqueTemplateName")^

Without the ^action^ calls within the context of the template you wouldn't be able to repopulate each includes different group listing. You don't need to reset the $IncludeSet at the start of the run as the '=' assignment overwrites all existing list date (whereas $IncludeSet = $IncludeSet + .... would add to it). Instead, you just clean up after the last include.

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.