0 votes
by (2.7k points)
edited by
I want to know how to use the <<replace>> macro to update a piece of text. Normally it is quite easy, however if I want to simply re-disply the same variable with an updated value, the <<replace>> method requires me to use many unnecessary passages and <<include>> macros. Is there a simple javascript hack or a widget that can simply update the contents of a <span>?

1 Answer

0 votes
by (68.6k points)

It should be as simple as something like the following:

<<replace "your selector here">>$variable<</replace>>

Or if you needed to something more complex—e.g. a method call or expression—like so:

<<replace "your selector here">><<print $variable.methodCall()>><</replace>>

 

by (23.6k points)
How would you go about if there are more than one instances of your selector? As far as I know <<replace>> only seems to affect the first instance.
by (68.6k points)
It shouldn't be any more complicated than using any selector other than an ID selector.
by (23.6k points)
Ah - I kept using ID, but with a class selector it works. Thanks.
by (2.7k points)

Not quite what I wanted... I basically have a large passage with many variables <progress> elements etc. and I want to update them with a single command like this:

<<update #id>>

Which is the equivilent of reloading that single part of the passage. This is not very clean code:

<span id="span"><progress value=100 max=1000></progress>
$Variable1
<progress value=200 max=1000></progress>
$Variable2</span>

<<replace #span>><progress value=100 max=1000></progress>
$Variable1
<progress value=200 max=1000></progress>
$Variable2<</replace>>

This is better:

<span id="span"><progress value=100 max=1000></progress>
$Variable1
<progress value=200 max=1000></progress>
$Variable2</span>

<<update #span>>

How would I make a widget or JavaScript macro that does that? (both examples would yeild the same result)

...