urgh.. brackets

64 views
Skip to first unread message

MagoArcade

unread,
Aug 4, 2019, 6:25:41 AM8/4/19
to tiddl...@googlegroups.com
Hi all,

Having problems constructing a string from various components. The output I'm looking for would be in this format (literal and to be stored in a tiddler field):

{"31ada977-900e-4751-8549-8320014ab42f":{"to":"45e0e73a-0bdb-4a18-8452-8fdb59407bc6","type":"Subtask Of"}}

My heavily abridged code:

\define TmapEdgesGen(tmapid reltype)
{"{{{ [[]make[%uuid%]] }}}":{"to":"$tmapid$","type":"$reltype$"}}
\end

....

<$select field="SearchTermDD" class="tw-edit-texteditor myTextEdit">
<$list filter="[regexp:<SearchTermWikid>]" emptyMessage="No Results" >
<option value=<<currentTiddler!!title>>><$view field='title'/></option>

....

<$select field="rel_type" class="tw-edit-texteditor myTextEdit">
<$list filter="[[$:/_DTrelTypes]indexes[]sort[title]]" variable="key">
<$set name="val" filter="[[$:/_DTrelTypes]getindex<key>]">
<option value=<<key>>><<key>></option>

....

<$set name="parentmapid" tiddler={{!!SearchTermDD}} field=tmap.id>

<$wikify name="tmaprelwikid" value="""<<TmapEdgesGen <<parentmapid>> {{!!rel_type}} >>""" >

DEBUG
ParentMapID: <<parentmapid>>
RelTypeID: {{!!rel_type}}
Tmap.rels: <<tmaprelwikid>>


<<!!rel_type>> can contain spaces

<<parentmapid>> will never contain spaces

The output I get is:

DEBUG

ParentMapID: 1bad2a3f-e5d7-4923-8bb1-73e2cdd36314

RelTypeID: Idea About

Tmap.rels:


I.e. nothing in <<tmaprelwikid>>


I've messed around with various permutations of brackets and quotes - cannot find anyway to get this working. 


Any help appreciated.


Jeremy Ruston

unread,
Aug 4, 2019, 7:02:52 AM8/4/19
to tiddl...@googlegroups.com
Hi MagoArcade

I’m not sure that I fully understand what you’re trying to do, but I can see a few red flags in the excerpts you’ve provided.

First, the core of this task is appears to be to substitute chunks of text into a template. This is one of those situations where text substitution via a macro is called for:

\define json-output()
{"$(id1)$":{"to":"$(id2)$","type":"$(type)$"}}
\end

<$var id1=..something.. id2=..something.. type=..something..>
<$action-setfield $tiddler="my tiddler" $field="my-field" $value=<<json-output>>/>
</$vars>

The macro definition uses $(var)$ syntax to refer to variable names that are substituted when the macro is subsequently evaluated.

For explanatory purposes, I’ve used a var widget to assign values to those variables, and then used the action-setfield widget to assign the result to a tiddler field.

With that outline in mind, I’ll briefly note a few issues with the code you provided:

My heavily abridged code:

\define TmapEdgesGen(tmapid reltype)
{"{{{ [[]make[%uuid%]] }}}":{"to":"$tmapid$","type":"$reltype$"}}
\end

....

<$select field="SearchTermDD" class="tw-edit-texteditor myTextEdit”>

Field names should be lowercase with dots, dashes, dollars and underscores.

<$list filter="[regexp:<SearchTermWikid>]" emptyMessage="No Results" >
<option value=<<currentTiddler!!title>>><$view field='title’/>

There’s no such construction as <<currentTiddler!!title>>. When used to quote attribute values, the double angle bracket syntax evaluates a macro name, not a tiddler text reference.

</option>

....

<$select field="rel_type" class="tw-edit-texteditor myTextEdit">
<$list filter="[[$:/_DTrelTypes]indexes[]sort[title]]" variable="key">
<$set name="val" filter="[[$:/_DTrelTypes]getindex<key>]">
<option value=<<key>>><<key>></option>

Here you’re using <<key>> to display the key within the option element. That syntax causes the content of the variable “key” to be wikified (ie wiki syntax like bold and italics would be honoured). It’s usually better to use <$text> or <$view> to display raw text.


....

<$set name="parentmapid" tiddler={{!!SearchTermDD}} field=tmap.id>

<$wikify name="tmaprelwikid" value="""<<TmapEdgesGen <<parentmapid>> {{!!rel_type}} >>""” >

The wikify widget isn’t needed in simple cases of text substitution. It’s only required if the functionality of the full wikitext parsing engine is required.

Sorry for being brief, feel free to ask followups.

Best wishes

Jeremy



DEBUG
ParentMapID: <<parentmapid>>
RelTypeID: {{!!rel_type}}
Tmap.rels: <<tmaprelwikid>>


<<!!rel_type>> can contain spaces

<<parentmapid>> will never contain spaces

The output I get is:

DEBUG

ParentMapID: 1bad2a3f-e5d7-4923-8bb1-73e2cdd36314

RelTypeID: Idea About

Tmap.rels:


I.e. nothing in <<tmaprelwikid>>


I've messed around with various permutations of brackets and quotes - cannot find anyway to get this working. 


Any help appreciated.



--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/87ed32ae-07bd-4e3b-9938-e9d9be87a293%40googlegroups.com.

MagoArcade

unread,
Aug 4, 2019, 7:52:23 AM8/4/19
to TiddlyWiki
Thanks Jeremy, that nudged me in the right direction. The key was rather than passing as parameters, set as vars in main body and use these in the macro. I'll be taking this approach rather than parameters from hereon in.

Working code (not tackled the other issues, but seems to be working without addressing those):


\define TmapEdgesGen()
{"$(randrelid)$":{"to":"$(parentmapid)$","type":"$(reltype)$"}}
\end


....

<!-- ADD NEW TIDDLER -->


<$vars reltype={{!!rel_type}}
randrelid
={{{ [[]make[%uuid%]] }}}
itemid
={{{ [[]make[%uuid%]] }}}
desctext
={{$:/_opNodeDetsEditText!!text}}>



<$set name="parentmapid" tiddler={{!!SearchTermDD}} field=tmap.id>


<$wikify name="myfinal" text=<<final>> >


DEBUG


ParentMapID: <<parentmapid>>


RelType: <<reltype>>


From Macro: <<TmapEdgesGen>>


<$button popup="bob" >Create Item


<$action-setfield $tiddler="$:/
_opTaskStore"
itemTitle=<<myfinal>>
desctext={{$:/_opNodeDetsEditText!!text}}
/>


<$action-setfield $tiddler="
$:/_opEditNode"
item.id=<<itemid>>
shorttext={{$:/
_opTaskStore!!taskname}}
description
=<<desctext>>
tags
={{$:/_opTaskStore!!tags}}
nodetype= {{!!nodetype}}
createdby={{!!createdby}}
managedby={{!!managedby}}
owner={{!!owner}}
assignedto={{!!assignedto}}
taskstatus={{!!taskstat}}
taskpercentage={{$:/
_opTaskStore!!taskpercentage}}
color
={{$:/_opTaskStore!!color}}
startdate= {{$:/
_opTaskStore!!startdate}}
duedate
=  {{$:/_opTaskStore!!duedate}}
stalldate =  {{$:/
_opTaskStore!!stalldate}}
completiondate
=  {{$:/_opTaskStore!!completiondate}}
tmap.edges=<<TmapEdgesGen>>
/
>


<$action-setfield $tiddler="$:/_opEditNode"
title
=<<myfinal>>
tmap
.id={{{ [[]make[%uuid%]] }}}
/>


<$reveal type='popup' state='bob' position='below'>
<div style='background-color:lightgreen'>
New Item created successfully:<br>
{{$:/_opTaskStore!!itemTitle}}<br>
<$link to={{$:/
_opTaskStore!!itemTitle}}>Click to View</$link>
</
div>
</$reveal>


<$action-setfield $tiddler="$:/
_opTaskStore"
taskname=""
tags=""
taskpercentage=0
/>


<$action-setfield $tiddler="
$:/_opNodeDetsEditText"
text=""
/
>


</$button>


</
$wikify>


</$set>


</
$vars>



Reply all
Reply to author
Forward
0 new messages