How to generate titles for childern of Tiddlers seting the title and a number based on the count widget.

136 views
Skip to first unread message

Jan

unread,
Aug 31, 2016, 6:22:55 PM8/31/16
to tiddlyWiki
Hi
I tried the following construction to achieve this:

\define titelsetzen() [[$(titel)$]]
\define StundenTitel() $(titel)$ - $(counter)$
\define neueStunde()
<$set name="counter" value=<<calc !!counter +1>>
<$vars tagthema={{!!thema}} titel={{!!title}}>
<$button>
<$action-setfield counter=<<counter>>/>
<$action-sendmessage
$message="tm-new-tiddler"
text={{$:/MetaTabs/MusterStunde}}
thema={{!!thema}} seminar={{!!seminar}}
title=<<StundenTitel>>
source=<<titelsetzen>>
tags="Stunde"/>
neu
</$button>
</$vars>
</$set>
\end

<<neueStunde>>

Unfortunately the title I get is just " - "
Does anyone see the mistake?

Thanks Jan

Tobias Beer

unread,
Sep 1, 2016, 2:21:22 AM9/1/16
to tiddl...@googlegroups.com
Hi Jan,
  1. Do you actually have calc @ tb5 installed?
    • Did you save and reload your wiki (since it's a JavaScript module)?
  2. Your $set widget openening tag appears to not have a closing ">".
    • Also, you could just use one $vars widget and not use $set at all.
Best wishes,

Tobias.

Jan

unread,
Sep 1, 2016, 5:26:22 AM9/1/16
to tiddl...@googlegroups.com
Thanks Tobi,
I thought calc was a core feature... a very  useful thing you did there.
Your help put me a great deal ahead...


Calc does not render if the counter-Field does not exist or is empty.
I am using this as a template so I need a switch for the first Child where the counter field won't exist:


\define titelsetzen() [[$(titel)$]]
\define StundenTitel() $(titel)$ - $(counter)$
\define neueStunde()
<$list filter="[all[current]!has[counter]]">
<$vars tagthema={{!!thema}} titel={{!!title}} counter="1" >
<$button>
<$action-setfield counter="1"/>

<$action-sendmessage
  $message="tm-new-tiddler"
  text={{$:/MetaTabs/MusterStunde}}
  thema={{!!thema}} seminar={{!!seminar}} 
  title=<<StundenTitel>>
  source=<<titelsetzen>>
  tags="Stunde"/>
Stunde hinzufügen
</$button>
</$vars>
</$list>
<$list filter="[all[current]has[counter]]">
<$button>
<$vars tagthema={{!!thema}} titel={{!!title}} counter=<<calc !!counter +1>> >

<$action-setfield counter=<<counter>>/>
<$action-sendmessage
  $message="tm-new-tiddler"
  text={{$:/MetaTabs/MusterStunde}}
  thema={{!!thema}} seminar={{!!seminar}} 
  title=<<StundenTitel>>
  source=<<titelsetzen>>
  tags="Stunde"/>
Stunde hinzufügen
</$vars>
\end




Am 01.09.2016 um 08:21 schrieb Tobias Beer:
Hi Jan,
    1. Do you actually have calc @ tb5 installed?
    2. Did you save and reload your wiki (since it's a JavaScript module)?
    1. your $set widget openening tag appears to not have a closing ">"
      • also, you could just use one $vars widget and not use $set at all
    Best wishes,

    Tobias.
    --
    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 tiddlywiki+...@googlegroups.com.
    To post to this group, send email to tiddl...@googlegroups.com.
    Visit this group at https://groups.google.com/group/tiddlywiki.
    To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/9f6b246b-4767-4f2c-8297-64c4cf3d0fae%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

    Tobias Beer

    unread,
    Sep 1, 2016, 4:14:26 PM9/1/16
    to tiddl...@googlegroups.com
    Hi Jan,
     
    Calc does not render if the counter-Field does not exist or is empty.

    I could extend calc, so that it would initialize the value
    when it would otherwise be undefined / NaN, e.g.:

    <<calc "0=>!!counter" +1>>

    Meaning:
    • if counter is undefined / NaN, initialize as 0
    • if counter is a number, add 1
    You could initialize with a numeric value of your choice:

    <<calc "7=>!!counter" +1>>

    I would make it so that whatever is left of "=>"
    would have to be numeric for the expression to be valid.

    With spaces in text references:

    <<calc "7=>with spaces!!counter" +1>>

    or:

    <<calc [[7=>with spaces!!counter]] +1>>

    Would that help?

    Best wishes,

    Tobias. 

    Tobias Beer

    unread,
    Sep 2, 2016, 1:31:31 AM9/2/16
    to TiddlyWiki
    Hi Jan,

    I have made an update of calc to allow initialization of undefined fields:

    Get it here: calc @ tb5 

    Implementation:
    <<calc "0=>!!counter" +1>>

    Meaning:
    • if counter is undefined / NaN, initialize as 0
    • if counter is a number, add 1

    Best wishes,

    Tobias. 

    Tobias Beer

    unread,
    Sep 2, 2016, 1:58:51 PM9/2/16
    to TiddlyWiki
    Hi again, Jan,

    I actually updated it again, so that both parameters value and by can be initialized.

    <<calc "2=>!!counter" * by:2=>!!counter>>

    Another oversight: calc now supports full text-references, not just those for fields.

    Get the update from here:


    Best wishes,

    Tobias.

    Jan

    unread,
    Sep 2, 2016, 6:36:12 PM9/2/16
    to tiddl...@googlegroups.com
    Hi Tobias,
    It is a little harder to understand but so much more elegant than my bulky workarround...
    I will replace it as soon as possible.

    Thanks a lot
    Jan
    --
    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 tiddlywiki+...@googlegroups.com.
    To post to this group, send email to tiddl...@googlegroups.com.
    Visit this group at https://groups.google.com/group/tiddlywiki.

    Tobias Beer

    unread,
    Sep 2, 2016, 7:22:15 PM9/2/16
    to TiddlyWiki
    Hi Jan,
     
    It is a little harder to understand but so much more elegant than my bulky workaround...

    I will replace it as soon as possible.

    The "by" parameter made it so much easier
    to simply define a calculation with fields.

    Take this example: 

    <<calc !!order +2>>

    How would you make it so that the 2
    can be read from some text-reference?

    See, you would need:
    • a helper macro
    • a helper variable
    • and then use the macrocall-widget to use calc
    \define op() +$(num)$

    <$vars num={{!!that-field}}>
    <$macrocall $name=calc value="!!order" operation=<<op>>/>
    </
    $vars>

    Oy, bummer, now you can't use calc
    anymore as an attribute to a widget!
    Plus, isn't that way too difficult?

    This, on the other hand, is much simpler:


    <<calc !!order + by:!!that-field>>

    And now you can add initialization on top:

    <<calc 0=>!!order + by:1=>!!that-field>>

    Not all that difficult, after all.

    Best wishes,

    Tobias.
    Reply all
    Reply to author
    Forward
    0 new messages