Still struggling with macros

Hi everyone

I want a button in page controls that creates a new tiddler with the following parameters, but I can’t get

\define sourcegrabpaste(tid:"") {{{ [[$:/.giffmex/Current.source.text]get[text]] }}}

to grab the text of $:/.giffmex/Current.source.text and paste it in the new tiddler’s text in place of $tid$ in the output of the button. Below is the button:

<$action-sendmessage $message="tm-new-tiddler" title=<<now "YYYY / 0MM / 0DD / 0hh:0mm:0ss /">> text="X  @@.graylinks <$link>**</$link>&nbsp;[[@|$tid$]] ### @@" />
{{$:/.giffmex/images/ampersand}}
</$button>

What am I doing wrong now?

Give this a shot:

\define newLink() X  <span class="graylinks"><$link>**</$link>&nbsp; [[@|$(sourceText)$]]  ###</span>

<$set name="sourceText" value={{$:/.giffmex/Current.source.text}}>
<$button>
<$action-sendmessage
   $message="tm-new-tiddler"
   title=<<now "YYYY / 0MM / 0DD / 0hh:0mm:0ss /">>
   text=<<newLink>>
/>
   &
</$button>
</$set>
  1. It’s easier to stick the entire line of new text all together as the macro.
  2. Putting the reference to the temp tiddler in a SET widget ensures the transclusion actually happens.
  3. Now you can also reference the SET’s variable inside the macro using the $(…)$ reference.
1 Like

Thanks Brian! With a couple cosmetic changes, that worked!

Every time someone gives me a solution, it looks totally different from the ones given to me before.

I will be studying this to understand it better. Thanks again!

@DaveGifford both your question and as a result @Brian_Radspinner answer seem more complex than they need to be so;

The tm-new-tiddler message and the ActionCreateTiddlerWidget are able to be used in many different ways. Your question did not use a simple common representation so you should not be surprised you get different looking answers.

Perhaps the following can help

  • I recently added an example to the bottom of WidgetMessage: tm-new-tiddler
    • Using tm-new-tiddler when using the param “template” includes the text field
  • Alternatively you could use the action create tiddler widget and give every parameter is own line
<$action-createtiddler $basetitle="Homemade Button" 
       tags="$:/tags/PageControls" 
       text={{$:/state/new-button-caption}}
      >
       <$action-navigate $to=<<createTiddler-title>>/>
</$action-createtiddler>
  • If you started from a clear starting place I think the answers will start to look similar.
  • I understand how you were some way along when you needed help, where you are then clouded by the problem and influences the way you ask your question. It is helpful to yourself/others if you simplify/standardise/spell out and often the mistake pops out.
1 Like