Skip to content

Instantly share code, notes, and snippets.

@reidgould
Created September 8, 2017 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reidgould/3b1c9f3e44276bfa65d78c5a5950ebe4 to your computer and use it in GitHub Desktop.
Save reidgould/3b1c9f3e44276bfa65d78c5a5950ebe4 to your computer and use it in GitHub Desktop.
Update of other gist about set widget value and filter attributes with correct and supported solution.
\define testValue()
Test With Spaces
\end
\define testValue_Bracketed()
[[$(testValue)$]]
\end
\define testVariable_Brackets()
[[$(testVariable)$]]
\end
\define testAlert()
<$set name="testResult" filter="[<testVariable>] +[remove<testValue_Bracketed>]"
value="failure"
emptyValue="success" >
<$action-createtiddler $basetitle="Alert" component="Alert from $(currentTiddler)$" tags="$:/tags/Alert" text=<<displayText>> />
</$set>
\end
\define displayText()
testVariable: $(testVariable)$<br>
testValue: $(testValue)$<br>
filter: <span style=font-size:0.75em; >`[<testVariable>] +[remove<testValue_Bracketed>]`</span><br>
result: $(testResult)$
\end
\define testAlert_enlist()
<$set name="testResult" filter="[enlist<testValue_Bracketed>] +[remove<testVariable>]"
value="failure"
emptyValue="success" >
<$action-createtiddler $basetitle="Alert" component="Alert from $(currentTiddler)$" tags="$:/tags/Alert" text=<<displayText_enlist>> />
</$set>
\end
\define displayText_enlist()
testVariable: $(testVariable)$<br>
testValue_Bracketed: $(testValue_Bracketed)$<br>
filter: <span style=font-size:0.75em; >`[enlist<testValue_Bracketed>] +[remove<testVariable>]`</span><br>
result: $(testResult)$
\end
\define testAlert_encoded()
<$set name="testResult" filter="[<testValue>] +[encodeuri[]] +[remove<testVariable_encoded>]"
value="failure"
emptyValue="success" >
<$action-createtiddler $basetitle="Alert" component="Alert from $(currentTiddler)$" tags="$:/tags/Alert" text=<<displayText>> />
</$set>
\end
\define displayText_encoded()
testVariable_encoded: $(testVariable_encoded)$<br>
testValue: $(testValue)$<br>
filter: <span style=font-size:0.75em; >`[<testVariable>] +[encodeuri[]] +[remove<testVariable_encoded>]`</span><br>
result: $(testResult)$
\end
<p>
<$button actions="""<$action-createtiddler $basetitle=<<testValue>> text="Text content." />""" >Create "<<testValue>>" Tiddler</$button>
<$button actions="""<$action-deletetiddler $tiddler=<<testValue>> />""" >Delete "<<testValue>>" Tiddler</$button>
</p>
<p>
Each of the following tests assign a testValue to testVariable. When the button is pressed, a listop attempts to remove the testVariable by using the original testValue.<br>
Press the Create button above before pressing test buttons.
</p>
<p>
<$set name="testVariable" value=<<testValue>> >
This test succeeds because the value is assigned to testVariable in the "value" parameter of set.<br>
Writing `<<testVariable>>` in WikiText outputs plain text:<br>
<<testVariable>> <br>
<$button actions="""<<testAlert>>""" >Run Test</$button>
</$set>
</p>
<p>
<$set name="testVariable" filter="[<testValue>]" >
This test fails because the value is assigned to testVariable in the "filter" parameter of set.<br>
Writing `<<testVariable>>` in WikiText outputs a wikilink:<br>
<<testVariable>> <br>
At first glance, this makes sense, as titles with spaces are usually displayed with double square brackets, and when parsed as WikiText that should display as a link.
But, note in the test output, that even though we add brackets to the plain value before operating on the passed variable, the test still fails.<br>
<$button actions="""<<testAlert>>""" >Run Test</$button>
</$set>
<br>
<$set name="testVariable" filter="[<testValue>]" >
This can still work if our case allows us to operate using an enlisted value, for example this test where we manually bracket and enlist testValue before comparing to testVariable, but will not for cases where the variable must contain the plain value (e.g. the suffix of an insertbefore operator).<br>
<$button actions="""<<testAlert_enlist>>""" >Run Test</$button>
</$set>
</p>
<p>
<$set name="testVariable_encoded" filter="[<testValue>] +[encodeuri[]]" >
A workaround is to URI encode the value before assigning it.This workaround is also limited in use because decoding into a variable it will still cause automatic enlisting, therefore any operations by necessity must encode entire lists to operate, and decode entire lists to save back to the list field.<br>
Writing `<<testVariable_encoded>>` in WikiText outputs plain text:<br>
<<testVariable_encoded>> <br>
<$button actions="""<<testAlert_encoded>>""" >Run Test</$button>
</$set>
</p>
<p>
Edit this tiddler and change the definition of "testValue" to "TestWithoutSpaces" to see that this only effects titles with spaces.
</p>
<p>
<$set name="testVariable" value=<<testValue>> >
<$set name="testVariable" value={{{ [<testVariable>] }}} >
UPDATE:<br>
The correct way to retrieve the value is the triple curly bracket operator.<br>
Writing `<<testVariable>>` in WikiText outputs plain text:<br>
<<testVariable>> <br>
<$button actions="""<<testAlert>>""" >Run Test</$button>
</$set>
</$set>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment