1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-02 18:23:28 +00:00
TiddlyWiki5/editions/tw5.com/tiddlers/wikitext/Substituted Attribute Values.tid
Saq Imtiaz 3825e2579f
Adds Text substitution support in widget attributes and new operator (#7526)
* feat: new text substitution support, first pass

* fix: use the widget method instead of evaluating a filter

* revert to earlier implementation that emulates macro syntax

* fix: capitalize comments

* feat: add support for triple backticks for substituted attributes

* docs: added docs for substitute operator

* chore: more docs tweaks

* docs: substituted attributes, refactored docs for widget attributes

* docs: fixed typo

* docs: more examples for substituted attributes

* docs: updated prior documentation on concatenating text and variables

* docs: documentation corrections

* Update editions/tw5.com/tiddlers/filters/examples/substitute Operator (Examples).tid

Co-authored-by: btheado <brian.theado@gmail.com>

---------

Co-authored-by: btheado <brian.theado@gmail.com>
2023-06-24 14:57:15 +01:00

46 lines
2.0 KiB
Plaintext

base-url: http://tiddlywiki.com/
created: 20230615050814821
modified: 20230615173033918
tags: [[Widget Attributes]] WikiText
title: Substituted Attribute Values
type: text/vnd.tiddlywiki
<<.from-version "5.3.0">>
Substituted attribute values can use two different styles of quoting:
* Single backticks <$codeblock code="attr=`value`"/>
* Triple backticks <$codeblock code="attr=```value```"/>
The value of the attribute will be the text denoted by the backticks with any of the placeholders for filter expressions and variables substituted with their corresponding values. Filter expression placeholders are substituted before variable placeholders, allowing for further variable substitution in their returned value.
<<.warning "Any other wiki syntax in that text will be left as-is.">>
|placeholder syntax|description|h
|`$(varname)$`|Text substitution of a variable. Undefined variables are replaced with an empty string. |
|`${ filter expression }$`|Text substitution with the first result of evaluating the filter expression. |
! Examples
!! Substituting a variable value into a string
<$macrocall $name=wikitext-example-without-html src='<$text text=`Hello there this is the tiddler "$(currentTiddler)$"`/>'/>
!! Substituting a variable value and the result of evaluating a filter expression into a string
<$macrocall $name=wikitext-example-without-html src='<$text text=`This tiddler is titled "$(currentTiddler)$" and was last modified on ${[{!!modified}format:date[DDth MMM YYYY]]}$`/>'/>
!! Concatenating strings and variables to create a URL
<$macrocall $name=wikitext-example-without-html src='
<$let hash={{{ [<currentTiddler>encodeuricomponent[]] }}}>
<a href=`http://tiddlywiki.com/#$(hash)$`>this tiddler on tiddlywiki.com</a>
</$let>'/>
!! Concatenating variables and a text reference to create a URL
<$macrocall $name=wikitext-example-without-html src='
<$let hash={{{ [<currentTiddler>encodeuricomponent[]] }}}>
<a href=`${ [{!!base-url}] }$#$(hash)$`>this tiddler on tiddlywiki.com</a>
</$let>'/>