Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Agent, Actions, Rules & Automation >> Creating a list in the text area
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1408839285

Message started by Stephen Hay on Aug 23rd, 2014, 8:14pm

Title: Creating a list in the text area
Post by Stephen Hay on Aug 23rd, 2014, 8:14pm

Hello,

I have a parent note with 25 children and some grandchildren and I would like to create a note that has for its text a list of the following attributes for all these notes

the $Name of the note
the $PageTitle of the note
the $Description of the note

I don't want aliases included.

I would then like to be able to export this to Excel in three columns $Name, $PageTitle, $Description so that I can check the coherence across the entire set.

Could someone help me with this please?

Many thanks,
Stephen

Title: Re: Creating a list in the text area
Post by Mark Anderson on Aug 24th, 2014, 3:27am

First the export bit, for which you'll use two templates in 'envelope and letter' form. The first exports the starting container and the second is called recursively to include each descendant.

If you don't know how to set up export templates I suggest adding any of the built-in ones before proceeding. You own't use the latter but it will set up the necessary prototype/containers for you.

In the following code examples, where you see '{tab}' you should replace it in your actual template code with a Tab character.

Make an template 'Tab-delim wrapper' in the Templates container. Give it this code:

Code:
Name{tab}Page Title{tab}Description
^children("Tab-delim item")^

What does this do? It exports a set of 2 tab separated column headers. Then, it tells Tinderbox to add the contents of all the note's children using the template "Tab-delim item". Children only? Yes - the next template solves the extra descendants.

Make an template 'Tab-delim item'. Give it this code:

Code:
^if($IsAlias==false)^^value($Name)^{tab}^value($PageTitle)^{tab}^value($Description)^^if($ChildCount)^
^children("Tab-delim item")^^endIf^^endIf^

N.B. a line return after the closing ^endIf^. The template first tests the note being exported is not an alias - if it is nothing happens. If the note isn't an alias, a line is added to the export with the note's $Name, $PageTitle and $Description values separated by tabs. The template then checks to see if the note has children. If it does, each of these is included using the same template. By this method, the export of the starting container adds all descendants.

In HTML inspector, you want to give the container an export extension of '.txt' instead of the default '.html'.

If you don't want to export the whole document, skip the last step. Set up the templates, select the source container for your export then switch its text pane to 'HTML'. Use Cmd+A and Cmd+C to select all the export 'code' (your tab-delim data) and copy it. Open TextEdit, make the new document plain text, and paste in the 'code' from the clipboard. Save the file with a '.txt' extension and you're ready to import the file to Excel Make. Or, you could select a new Excel worksheet, select A1 and the paste the data direct from the clipboard.

Title: Re: Creating a list in the text area
Post by Mark Anderson on Aug 24th, 2014, 3:44am

Add a String attribute $ItemDetails to your document. Add a prototype "pItem" to your document. Set all descendants of your container of the 25 notes to use the new prototype. Give the prototype this $Rule:

$ItemDetails = $Name + "\n" + $PageTitle + "\n"  + $Description + "\n"

The "\n" bits simple tell TB to add a line return. Now in the main container set this $Rule:

$Text = collect(descendants,$ItemDetails).format("\n")

The container's text will now be a list of successive sets of lines of Name/Page title/Description with a blank line before the next set.

Title: Re: Creating a list in the text area
Post by Stephen Hay on Aug 24th, 2014, 5:53am

Where would I be without you...! Many, many thanks...

As the children already use a prototype, I presume I can just add the Rule to the current Prototypes?

Title: Re: Creating a list in the text area
Post by Mark Anderson on Aug 24th, 2014, 7:41am

Add to an existing prototype's $Rule? Yes, absolutely.

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.