[TW5] concatenate field values in macro

162 views
Skip to first unread message

Bob Flandard

unread,
Oct 10, 2015, 7:38:32 PM10/10/15
to TiddlyWiki
Hello,

I've tried to create an external link macro that concatenates the tiddler fields "path" and "file"

My effort below doesn't work ( it only sees {{!!path}} and not {{!!file}} ), and it's not really what I want. I want a single macro that I can call to make an external link that creates its href value by concatenating the "path" and "file" fields of the tiddler it's called from. If it's possible to do this using [ext[pretty name|URI]] then all the better (but I have tried and failed).


\define .dlink-ex()
<a href=$(sentence)$ class="tc-tiddlylink-external" target="_blank">goat</a>
\end

<$set name="sentence" value="{{!!path}}{{!!file}}">
<<.dlink-ex>>
</
$set>


Thanks, Bob




Tobias Beer

unread,
Oct 10, 2015, 7:44:33 PM10/10/15
to tiddl...@googlegroups.com
Hi Bob,

Try either the VarsWidget...

\define .dlink-ex()
<a href="$(path)$$(file)$" class="tc-tiddlylink-external" target="_blank">goat</a>
\end

<$vars path={{!!path}} file={{!!file}}>
<<.dlink-ex>>
</$vars>

...or the MacroCallWidget which should work in your case as well...

\define .dlink-ex(path, file)
<a href="$path$$file$" class="tc-tiddlylink-external" target="_blank">goat</a>
\end

<$macrocall $name=".dlink-ex" path={{!!path}} file={{!!file}} />

Best wishes,

— tb

Bob Flandard

unread,
Oct 11, 2015, 5:23:22 AM10/11/15
to TiddlyWiki
Hello tb,

Thanks for that!

I haven't got my head around the macro mechanism and what's allowed with parameter substitution, but I notice that wrapping a macro around the macrocall line does what I want. It allows using the nice shorthand <<macroName>> macro calling syntax without having to explicitly pass the path and file arguments. But it leaves me feeling that I've jumped through a hoop, turned around and jumped back again.


\define .dlink-ex(pretty, path, file)
<a href="$path$$file$" class="tc-tiddlylink-external" target="_blank">$pretty$</a>
\end

\define pig(pretty)
<$macrocall $name=".dlink-ex" pretty=$pretty$ path={{!!path}} file={{!!file}} /
>
\end

<<pig "earwig">> works


\define .dlink-bad(pretty)
<a href="{{!!path}}{{!!file}}" class="tc-tiddlylink-external" target="_blank">$pretty$</a>
\end

<<.dlink-bad "earwig">> doesn't work


All the best, Bob

Tobias Beer

unread,
Oct 11, 2015, 7:10:04 AM10/11/15
to TiddlyWiki
Hi Bob,

Try to pay more attention to not forgetting the quotes around your parameters.
To be safe you may even want to chose triple double quotes.

Best wishes,

— tb 
Reply all
Reply to author
Forward
0 new messages