compare field value to title in filter

77 views
Skip to first unread message

Robin

unread,
Apr 30, 2018, 5:37:53 PM4/30/18
to TiddlyWiki
I was trying the new form tiddler from inmysocks
And it works great except it overwrite a existing tiddler if it has the same name.
I adapted it a bit but can’t get this filter part to work

[title[TiddlerName]is[tiddler]]


This works fine but if I try to reference to: $:/state/NewTiddlerForm!!name_temp
I’ve got a problem

[title[{{$:/state/NewTiddlerForm!!name_temp}}]is[tiddler]]


I know this is wrong but I don’t know why.

That part of the filtersyntax eludes me.

TonyM

unread,
Apr 30, 2018, 8:16:25 PM4/30/18
to TiddlyWiki
I can't confirm this but try [title[{$:/state/NewTiddlerForm!!name_temp}]is[tiddler]]

Single curly braces in filters.

Tony

Robin

unread,
Apr 30, 2018, 9:15:55 PM4/30/18
to TiddlyWiki
Thx Tony 

But the sad thing is, it didn't work.

Maybe I screwed something up somewhere else I'll post the full modified code.

\define ShowButton()
Press this button and the tiddler will be created and opened so you can view it.


<$button>Create Tiddler
<$action-setfield $tiddler={{$:/state/NewTiddlerForm!!name_temp}} text={{$:/state/NewTiddlerForm!!text}} description={{$:/state/NewTiddlerForm!!description}} tags={{$:/state/NewTiddlerForm!!tags}}/>
<$action-navigate $to={{$:/state/NewTiddlerForm!!name_temp}}/>
<$action-setfield $tiddler='$:/state/NewTiddlerForm' name_temp='' text='' description='' tags=''/>
</$button>
<$button>Clear Form
<$action-setfield $tiddler='$:/
state/NewTiddlerForm' name_temp='' text='' description='' tags=''/>
</$button>
\end


\define ShowExist() @@color:red; ''This tiddler exists pick a different name''@@

Here it goes wrong

\define filter() [title[{$:/state/NewTiddlerForm!!name_temp}]is[tiddler]]

Here is the rest of it

!!Step 1 - ''Give the tiddler a name''


---
<$edit-text class='tc-edit-texteditor' tiddler='$:/state/NewTiddlerForm' field='name_temp' placeholder='Tiddler Name'/><br>


!!Step 2 - ''Fill in tiddler text''


---
You can use any WikiText here, see [[Wiki Formatting - text, tables, etc.]] for some easy examples of text formatting.
You can resize the exiting field by clicking and dragging the lower right corner.


<$edit-text class='tc-edit-texteditor' tiddler='$:/state/NewTiddlerForm' field='text' placeholder='Tiddler Text'/><br>


!!Step 3 - ''Give the tiddler a description'' (optional)


---
This can be used as a short description or summary of what each tiddler is. It can be useful in lists.


<$edit-text class='tc-edit-texteditor' tiddler='$:/state/NewTiddlerForm' field='description' placeholder='Tiddler Description'/><br>


!!Step 4 - ''Add a tag or tags to the tiddler'' (optional)


---
Tags are used for the table of contents, so it may be advisable to add tags to new tiddlers. For example, if you wanted to add a tiddler that would be displayed under 'Tools' in the table of contents you would add the 'Tools' tag to the tiddler.


<$select tiddler='$:/state/NewTiddlerForm' field='add_or_create_tag'>
<option value='existing'>Add existing tag</option>
<option value='create'>Add a new tag</
option>
</$select>
<$reveal type=match state='$:/
state/NewTiddlerForm!!add_or_create_tag' text='create'>
New Tag Name: <$edit-text tiddler='
$:/state/NewTiddlerForm' field='tag_temp' placeholder='New Tag'/><$fieldmangler tiddler='$:/state/NewTiddlerForm'>
<$button>
<$action-sendmessage $message='
tm-add-tag' $param={{$:/state/NewTiddlerForm!!tag_temp}}/>
<$action-setfield $tiddler='
$:/state/NewTiddlerForm' $field='tag_temp' $value=''/>Add Tag
</$button>
</$fieldmangler><br>
</$reveal>
<$reveal type='
match' state='$:/state/NewTiddlerForm!!add_or_create_tag' text='existing'>
Tag to add: <$select tiddler='
$:/state/NewTiddlerForm' field='tag_temp'>
<$list filter='
[tags[]sort[title]]'>
<option><$view field='
title'/></option>
</$list>
</$select>
<$fieldmangler tiddler='
$:/state/NewTiddlerForm'>
<$button>
<$action-sendmessage $message='
tm-add-tag' $param={{$:/state/NewTiddlerForm!!tag_temp}}/>Add Tag
</$button>
</$fieldmangler>
<br>
</$reveal>
List of current tags:<br>
<$fieldmangler tiddler='
$:/state/NewTiddlerForm'>
<$set name=tiddlerEditing value='
$:/state/NewTiddlerForm'>
<$list filter='
[[$:/state/NewTiddlerForm]tags[]]'><$view field='title'/> <$button>Remove Tag<$action-sendmessage $message='tm-remove-tag' $param=<<currentTiddler>>/></$button><br> </$list>
</$set>
</$fieldmangler>


!!Step 5 - ''Create the tiddler''


---
<$list filter=<<filter>> emptyMessage=<<ShowButton>>> <<ShowExist>> </$list>

As I said before only the parts to check for the titel I added
All the rest is done by far beter ppl than me.


TonyM

unread,
Apr 30, 2018, 9:24:27 PM4/30/18
to TiddlyWiki
This referencing thing is not my strong point

Try  [title{$:/state/NewTiddlerForm!!name_temp}is[tiddler]]

I also avoid macro names that are reserved wors eg filter bu if that how it was already designed go with it.

Regards
Tony

Robin

unread,
Apr 30, 2018, 9:46:37 PM4/30/18
to TiddlyWiki
Yay it works thanks a lot for this.

Also good tip for the macro names, I didn't think of that.

But I still don't know why this works.
can I allways replace [ ]  with { }  in a filter ?

That part of the syntax eludes me a bit.


TonyM

unread,
Apr 30, 2018, 9:58:25 PM4/30/18
to TiddlyWiki
Robin,

This is an area with a gap in the doco, I is hard to find it in one place. here are a few




A great explanation from Jeremy

In TiddlyWiki *content*, variables are referenced using <<variableName>>.  The double-bracket syntax is used to avoid conflicts with standard HTML syntax (i.e., <b> starts normal HTML bold formatting, while <<b>> embeds the value of a TiddlyWiki variable named "b")

However, within TiddlyWiki *filters*, there is no need doubling the brackets, as HTML is not allowed *within* the filter, so only single <variableName> is used.

...and why I don't have to wrap <fieldname> with [<fieldname>] before giving it to split. 

Think of the brackets in filters as part of the operand itself rather than a "container" for the operand.  The type of bracket indicates the type of operand being used:
   use [...] for literal values, e.g., [texthere] 
   use {...} for field references, e.g., {!!fieldname}
   use <...> for variables e.g. <currentTiddler>

Thus, to split the literal text, "sometext", you could write:
   [title[sometext]splitbefore[t]removesuffix[t]]
you would get "some" as a result.

If the value "sometext" is stored in a field named "somefield" in the current tiddler, you could write:
  [{!!somefield}splitbefore[t]removesuffix[t]]

and, if the value "sometext" is stored in a variable named "somevariable", you could write:
  [<somevariable>splitbefore[t]removesuffix[t]]

As a slightly more complex example, suppose the value to split on was also stored in a variable.  Then you could write:
  [<somevariable>splitbefore<othervariable>removesuffix<othervariable>]

Regards
Tony

Mark S.

unread,
Apr 30, 2018, 10:58:28 PM4/30/18
to TiddlyWiki
This explains filter parameters, and when you can use what kind of enclosure (e.g. <>,[],{} )

https://tiddlywiki.com/#Filter%20Parameter

-- Mark
Reply all
Reply to author
Forward
0 new messages