Indirect Addressing using a variable instead of a field name

I’m trying to get the value of a field using the following statement

Longitude= {{{[<currentTab>get[parentGun]get[Longitude]] }}}

This works as long as parentGun is set to the title of an existing tiddler.

However, the title of the existing tiddler is not in the parentGun field cause I can’t see how to set this field without user input. So I have stored the title in a variable and amended the statement to

Longitude= {{{[<currentTab>get[<parentgunID>]get[Longitude]] }}}

This does not return the value of the longitude field, I assume because get only looks at field names and not variables.

Can anyone show me how to do this please.

bobj

Two things:

  • The parameter for the get filter is supposed to be a fieldname, not a tiddler title.

  • When specifying a filter parameter, the brackets surrounding the parameter indicate how that parameter value is to be processed:

    • Use square brackets around literal values (e.g., get[parentGun])
    • Use angle brackets around variable references (e.g., get<parentgunID>)
    • Use curly brackets to retrieve the value from a field reference (e.g., get{!!somefieldname})

-e

Bugger, those pesky brackets again. I thought I had conquered them but obviously, too cocky!!!

Thanks @EricShulman , without your continued advice I would not be as far along my journey.

Bobj

@EricShulman, can you provide some advice as to how to get this code to work or maybe an alternate process.

<$let
    parentgunID=<<currentTiddler>>
>

<$list 
filter="[<currentTab>caption[Map]]" >

Longitude= {{{ [<currentTab>get<parentgunID>get[Longitude]] }}}

Latitude= {{{ [<currentTab>get<parentgunID>get[Latitude]] }}}
</$list>

What I am trying to do is:

from a tiddler with a unique ID and displaying a tabbed area, click on a tab titled ‘Map’ and from the viewtemplate for the Map tiddler, extract the values of the field, Longitude and Latitude from the parent tiddler so that I can render a map of the location.

The code I provided is the code in the viewtemplate.

The variable, parentgunID, definitely contains the title of the main tiddler cause if I display that variable, the crrect title is displayed.

I know I could just create a tiddler called ‘gunID_Map’ where gunID is the title of the main tiddler, but I am trying to avoid that and just have a single Map tiddler for all gun tiddlers.

This problem was the source of my questions related to Tiddler X Field Y value Z cause my initial idea was to store the main tiddler title in a field and then use it subsequently. But I cant get that to work either.

Hope you can provide a workaround.

You can access a copy of the TW at http://cultconv.neocities.org/ArtilleryRegister/index.html

You should look at the record for the gun RAAHC3. The viewtemplate is $:/TLS/ViewTemplateGun

bobj

How can the wiki be switched to editor mode. There are no edit buttons, so it’s hard to see the code.

Ah, yes, sorry, my mistake. Editor mode is only switched on for accessing the wiki through the file protocol. Download it to your computer and then it should be ok except no images will be displayed.

Anyway, I have a solution to my problem. Not sure why I didn’t think of it before.

If I can store the parent tiddlers title, I can also store the value of the other fields in variables and then access them in the viewtemplate code. Obvious really. Just goes to show, you get focussed on one way and don’t see any other.

Bobj

So – Is this issue resolved?

1 Like

I have a work around. I’m still interested in a solution to the code as shown for my own education but recognise that people may be too busy.

If I could get the code to work, then I’d have a more generic solution that would cut down on the number of tiddlers in the final wiki by two thirds. And it would be more elegant.

Bobj