So with the printf[] operator I attached which is not a part of the TW core, $(varname)$ is replaced by a variable called varname if it exists, just like in macros. So in the example above $(accumulator)$ is replaced with the value of the variable accumulator
$n$ is replaced by the nth operand, zero based. So $0$ is replaced by the first operand, $1$ by the second operand. This again takes inspiration from macros and how macro parameters are replaced, but instead of using the name of a parameter we use the position of the operand. printf can handle an unlimited and flexible number of operands. This might not be something everyone would find intuitive, however it has been very useful for me in my own wikis. On Saturday, May 15, 2021 at 8:08:32 PM UTC+2 Mohammad wrote: > On Sat, May 15, 2021 at 8:33 PM Saq Imtiaz <[email protected]> wrote: > >> Just in the interest of thoroughness, option 3 from my post above can be >> further simplified to: >> >> <$button> save to a single tiddler >> <$vars template=" >> $(accumulator)$ >> !! $0$ >> >> $1$ >> "> >> <$action-setfield $tiddler="report" text={{{ [tag[About]] >> :reduce[<template>printf{!!title},{!!text}] }}}/> >> </$vars> >> </$button> >> >> However, the previous form makes it easier to understand how reduce is >> being used if one is not used to it. >> > > Lovely! I need to go through this! The $0$ and $1$ as place holder seems > to create a lot of flexibility! > > > >> On Saturday, May 15, 2021 at 4:39:12 PM UTC+2 Mohammad wrote: >> >>> WOW, great solution Saq! >>> >>> If we could have some good CSS for print in TW, then we could produce >>> wonderful output in PDF format! >>> >>> >>> >>> Best wishes >>> Mohammad >>> >>> >>> On Sat, May 15, 2021 at 2:11 PM Saq Imtiaz <[email protected]> wrote: >>> >>>> Below are three different ways to do this using reduce and without >>>> wikify. The last one uses a custom filter printf[] that is attached. >>>> Note that you can use a tiddler for your template as well. >>>> >>>> *#1 - addprefix galore* >>>> >>>> <$button> save to a single tiddler >>>> <$vars lb=" >>>> "> >>>> <$action-setfield $tiddler="report" text={{{ [tag[About]] >>>> :reduce[get[text]addprefix<lb>addprefix<lb>addprefix{!!title}addprefix[!!]addprefix<lb>addprefix<accumulator>] >>>> >>>> }}}/> >>>> </$vars> >>>> </$button> >>>> >>>> *#2 - search-replace* >>>> >>>> <$button> save to a single tiddler >>>> <$vars template=" >>>> !! _TITLE_ >>>> >>>> _TEXT_ >>>> "> >>>> <$action-setfield $tiddler="report" text={{{ [tag[About]] >>>> :reduce[<template>search-replace:gi[_TITLE_],{!!title}search-replace[_TEXT_],{!!text}addprefix<accumulator>] >>>> >>>> }}}/> >>>> </$vars> >>>> </$button> >>>> >>>> *#3 - printf[]* >>>> >>>> <$button> save to a single tiddler >>>> <$vars template=" >>>> !! $0$ >>>> >>>> $1$ >>>> "> >>>> <$action-setfield $tiddler="report" text={{{ [tag[About]] >>>> :reduce[<template>printf{!!title},{!!text}addprefix<accumulator>] }}}/> >>>> </$vars> >>>> </$button> >>>> >>>> -- >>>> >>> You received this message because you are subscribed to the Google >>>> Groups "TiddlyWiki" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> >>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/tiddlywiki/dd5d5a24-44ab-4c7a-8934-fc2cc1a79771n%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/tiddlywiki/dd5d5a24-44ab-4c7a-8934-fc2cc1a79771n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "TiddlyWiki" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/tiddlywiki/8793816d-56b4-456e-b2f8-d75faa837fccn%40googlegroups.com >> >> <https://groups.google.com/d/msgid/tiddlywiki/8793816d-56b4-456e-b2f8-d75faa837fccn%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/e5cbe63a-59c4-44c8-81e9-322d6b6d0878n%40googlegroups.com.

