diff --git a/editions/tw5.com/tiddlers/howtos/Concatenating text and variables using macro substitution.tid b/editions/tw5.com/tiddlers/howtos/Concatenating text and variables using macro substitution.tid index 9d6ebf028..732315ea1 100644 --- a/editions/tw5.com/tiddlers/howtos/Concatenating text and variables using macro substitution.tid +++ b/editions/tw5.com/tiddlers/howtos/Concatenating text and variables using macro substitution.tid @@ -1,5 +1,5 @@ created: 20160424150551727 -modified: 20190115162340362 +modified: 20211230153027382 tags: Learning title: Concatenating text and variables using macro substitution type: text/vnd.tiddlywiki @@ -9,9 +9,7 @@ It's a frequent use case in ~TiddlyWiki that you will want to put the results of You might, for instance want to set up a template for your customer database, where links will automatically refer to additional contact information about your customer. Inside your tiddler, you might try something like this: - -|warning|k -|@@font-size:1.5em;⚠@@ Warning:
Don't do it this way!| `[[Additional Info|<>-Contact]]` | +<<.bad-example "`[[Additional Info|<>-Contact]]`">> But that won't work. If you try this, the link will be interpreted very literally, and will attempt to take you to: @@ -29,9 +27,7 @@ Create a macro at the top of the tiddler like this: You might be tempted to invoke the new macro like this: -|warning|k -|@@font-size:1.5em;⚠@@ Warning:
Don't do it this way!| `<> >>` | - +<<.bad-example "`<> >>`">> But if you do, you will find that `<>` doesn't get rendered, but instead gets passed literally. @@ -53,10 +49,4 @@ Notice that in this case we don't pass an argument. Instead, we reference the va ``` <> -``` - - +``` \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/system/doc-macros.tid b/editions/tw5.com/tiddlers/system/doc-macros.tid index a745efe93..226a1ce35 100644 --- a/editions/tw5.com/tiddlers/system/doc-macros.tid +++ b/editions/tw5.com/tiddlers/system/doc-macros.tid @@ -1,5 +1,5 @@ created: 20150117152607000 -modified: 201804111739 +modified: 20211230150413997 tags: $:/tags/Macro title: $:/editions/tw5.com/doc-macros type: text/vnd.tiddlywiki @@ -113,6 +113,20 @@ This is an example tiddler. See [[Table-of-Contents Macros (Examples)]]. \end +\define .bad-example(eg) + + + + + + + +
Warning:
Don't do it this way!
+ +$eg$ +
+\end + \define .link-badge(text,link,colour) > class="doc-link-badge" style="background-color:$colour$;" target="_blank" rel="noopener noreferrer"><$text text=<<__text__>>/> \end diff --git a/editions/tw5.com/tiddlers/system/doc-styles.tid b/editions/tw5.com/tiddlers/system/doc-styles.tid index 277cd88d6..f7cd9594e 100644 --- a/editions/tw5.com/tiddlers/system/doc-styles.tid +++ b/editions/tw5.com/tiddlers/system/doc-styles.tid @@ -1,5 +1,5 @@ created: 20150117152612000 -modified: 20211124164948726 +modified: 20211230150725145 tags: $:/tags/Stylesheet title: $:/editions/tw5.com/doc-styles type: text/vnd.tiddlywiki @@ -133,6 +133,10 @@ td svg { padding-left: 20px; } +.doc-bad-example code, .doc-bad-example pre, table.doc-bad-example { + background-color:#ffff80; +} + .doc-table th, .doc-table tr { vertical-align: top; } diff --git a/editions/tw5.com/tiddlers/wikitext/Linking in WikiText.tid b/editions/tw5.com/tiddlers/wikitext/Linking in WikiText.tid index 037daa821..52201129b 100644 --- a/editions/tw5.com/tiddlers/wikitext/Linking in WikiText.tid +++ b/editions/tw5.com/tiddlers/wikitext/Linking in WikiText.tid @@ -1,6 +1,6 @@ caption: Linking created: 20131205155230596 -modified: 20160607095245257 +modified: 20211230145939554 tags: WikiText title: Linking in WikiText type: text/vnd.tiddlywiki @@ -80,3 +80,40 @@ You can also use the extended syntax to force an external link: See the LinkWidget for details of the underlying widget used to implement tiddler links, including macros that can be used to customise its behaviour. +! Generating dynamic links + +[[Linking in WikiText]] does not lend itself well to creating dynamic links. The reason is because this WikiText link: + +``` +[[link to myself|Linking in WikiText]] +``` +is shorthand for using the LinkWidget and TextWidget like this: + +``` +<$link to="Linking in WikiText"> + <$text text="link to myself"/> + +``` +Since both the link title ("link to myself") and the link target ("Linking in ~WikiText") are used as widget attributes, no WikiText expansion takes place. + +For example, an attempt to use a [[reference|TextReference]] and a [[variable|Variables]] to dynamically generate a link like this: + +<<.bad-example "`[[{{!!caption}}|<>]]`">> + +is the same as trying to use the LinkWidget and TextWidget like this: + +<<.bad-example """``` +<$link to="<>"> + <$text text="{{!!caption}}"/> + +```""">> + +This will not work as desired. Content inside of quoted widget attributes is [[treated as a literal value|HTML in WikiText]] and protected from WikiText expansion, so it will render like this: + +<<.bad-example "[[{{!!caption}}|<>]]">> + +In order to get the desired result, the LinkWidget can be used directly like this: + +<>>{{!!caption}}">> + +See also another example of [[constructing dynamic links|Concatenating text and variables using macro substitution]]. \ No newline at end of file