Re: [tw] SelectWidget and tm-remove-tag/tm-add-tag actions

121 views
Skip to first unread message

Xavier Cazin

unread,
Mar 11, 2018, 6:58:44 AM3/11/18
to tiddl...@googlegroups.com
Hi Mike,

There are a few syntactic mistakes in your code (@action-sendmessage instead of $action-sendmessage, and calling style-actions while you defined style_actions). Also, the actions attribute in $select should be a text, so you should write actions="<<style_actions>>".

But the main flaw seems to be that you assume in style_actions that the currentTiddler will take the value of the selected option, which is not the case: selected options are only saved in the tiddler field that you set in the "tiddler" attribute.

Cheers,
Xavier.
P.S. Regarding your dynamic stylesheet problem, what about applying custom styles by tag? https://tiddlywiki.com/#How%20to%20apply%20custom%20styles%20by%20tag

-- Xavier Cazin

On Sat, Mar 10, 2018 at 10:10 PM, Michael Wiktowy <mwik...@gmail.com> wrote:
Hi,

I either have a fundamental misunderstanding about tm-* action type action messages, fieldmangler or triggering actions with a select widget and I'm hoping that someone can set me straight or point me to an example of their use together because the example in the default TiddlyWiki is not illuminating on tm-* actions and "event.param"s. My code snippet:

\define indirect_transclude() <$transclude tiddler='$:/temp/print_proof' field='template_style'/>

\define style_actions()

<$list filter='[tag[mystyle]]'>
<$fieldmangler>
<@action-sendmessage $message='tm-remove-tag' param='$:/tags/Stylesheet'/>
</$fieldmangler>
</
$list>

<$wikify name="indirect" text=<<indirect_transclude>>>
<$fieldmangler tiddler=<<indirect>>>
<@action-sendmessage $message='tm-add-tag' param='$:/tags/Stylesheet'/>
</$fieldmangler></$wikify>

\end

<$select tiddler='$:/temp/print_proof' actions=<<style-actions>>>
<$list filter='[tag[template]]'>
<option value=<<currentTiddler>>><$view field='title'/></option>
</$list>
</
$select>

I am trying to make a mailing label sheet generator.

I am using the selectwidget to pick between various templates and have their tiddler title put into '$:/temp/print_proof' for a subsequent print proof page to display them. That seems to work fine.

Struggle as I have to have multiple different active @media print {} CSS rules running for different templates, it seems that you cannot. So I wanted the SelectWidget to also remove all the '$:/tags/Stylesheet' tags from 'mystyle' tagged tiddlers that will be paired with the templates (by putting their title in the template's template_style field) and just adding that tag to the one template that is selected. That way future templates could be easily added for different sheet layouts and be paired either with existing @media print stylesheets that work or a new one.

However, even the first part of the style_actions macro doesn't work to strip the Stylesheet tags. The $wikify widget was something that I needed to do for the proof sheet display a tiddler that was indirectly referenced in the '$:/temp/print_proof' tiddler so I figured that I would need it here to indirectly reference the stylesheet title in the template field.

Anyone have an idea where my train of thought has derailed?

/Mike

--
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+unsubscribe@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/362d9d08-80c4-4917-9a2f-4d146983d13e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark S.

unread,
Mar 11, 2018, 9:56:38 AM3/11/18
to TiddlyWiki
Hi Xavier,

I had also prepared a response for Mike, but then his post was deleted. Perhaps he decided to rework his code?

In case anyone is still interested, here's the code I came up with. But, as you commented, the applied new tag isn't tied to any selection option, so it may be of limited use.

One thing that was interesting, looking at the code for the SelectWidget, it appeared to me that all the widgets may have the "actions" string, and the content (as shown below) doesn't have to consist of just action widgets.

-- Mark

\define style-actions()
<$list filter='[tag[HelloThere]]'>
<$fieldmangler>
<$action-sendmessage $message=tm-remove-tag  $param="MyTag"/>
</$fieldmangler>
</
$list>

<$fieldmangler tiddler={{$:/temp/print_proof!!template_style}}>
<$action-sendmessage $message='tm-add-tag' $param='$:/tags/Stylesheet'/>
</$fieldmangler>


\end


<$select tiddler='$:/
temp/print_proof' actions=<<style-actions>>>
<$list filter='
[tag[HelloThere]]'>

<option value=<<currentTiddler>>><$view field='
title'/></option>
</$list>
</$select>

-- Xavier Cazin

To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.

Michael Wiktowy

unread,
Mar 13, 2018, 12:11:39 AM3/13/18
to TiddlyWiki
Thank you both Mark and Xavier. After I posted and scratched my head I realized (like you pointed out) that there were huge syntax errors in my code ... missing $ and @ when there should have been $ ... I think that I have been staring at too many @page rule websites struggling to make my n-up layout work. Once I corrected those typos, I could make progress and things worked. I thought that I had deleted my post before anyone had viewed it but I guess not. BTW my final working code turned out to be:

\define indirect_transclude() <$transclude tiddler="$:/temp/print_proof"/>


\define style_actions()
<$list filter="[tag[mystyle]]">
<$fieldmangler>
<$action-sendmessage $message="tm-remove-tag" $param="$:/tags/Stylesheet"/>
</$fieldmangler>
</
$list>


<$wikify name="indirect" text=<<indirect_transclude>>>
<$set name="currentTemplate" tiddler=<<indirect>> field="template_style">
<$fieldmangler tiddler=<<currentTemplate>>>

<$action-sendmessage $message="tm-add-tag" $param="$:/tags/Stylesheet"/>
<
/$fieldmangler>
<$set></
$wikify>
\end

<$select tiddler='$:/temp/print_proof' actions=<<style_actions>>>
<option>---Choose a Template---</option>

<$list filter='[tag[template]]'>
<option value=<<currentTiddler>>><$view field='title'/></option>
</$list>
</
$select>

This allowed me to activate the correct stylesheet base on what was associated with the selected template. The crazy double transclusion is due to the stylesheet tiddler name is in the "template_style" field in the tiddler referenced in "$:/temp/print_proof", which is not a field in "$:/temp/print_proof" itself. I will post the resulting tool somewhere soon. The last puzzle to solve is the n-up layout issue that I am having listed in another thread if you are willing to tackle another puzzle ... I guarantee this one is not solved.

Thanks again,
/Mike
Reply all
Reply to author
Forward
0 new messages