Use variable to call a js macro

I defined a js macro to generate text output and then use in another widget. The wikitext below is working for me.

<$set name="data-daylength" value=<<e_daylength latitude:"27">>>
  <$htmlwidgets type="echarts4r" data=<<data-daylength>> uuid="htmlwidget-9e88bb152f72bbc8b7f4" />
</$set>

In next step, I want to replace latitude from another variable. The following test is not working for me


<$set name="latitude1" value="-27">
  <$set name="data-daylength" value=<$transclude $variable="e_daylength" latitude=<<latitude1>> >
	    <<data-daylength>>
      <$htmlwidgets type="echarts4r" data=<<data-daylength>> uuid="htmlwidget-9e88bb152f72bbc8b7f4" />
  </$set>
</$set>

Any suggestions?

e_daulength is a js macro return json string:

(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

/*
Information about this macro
*/

exports.name = "e_daylength";

exports.params = [
	{name: "latitude"}
];

/*
Run the macro
*/
exports.run = function(latitude) {
	latitude = latitude || latitude.getVariable("currentTiddler");
	var output = {
		"x": {
		}
	};
	return JSON.stringify(output);
};

})();

you cannot use widgets as attributes

is not used in your macro

Thanks I will use it, this just is a test code.

Thanks, I get your point. But my question is whether it is possible to pass latitude as a variable.

You might find something like this will work:

<$let
  data-daylength=<<e_daylength latitude:"27">>
>
  <$htmlwidgets
    type="echarts4r"
    data="""<<data-daylength>>"""
    uuid="htmlwidget-9e88bb152f72bbc8b7f4"
  />
</$let>

<$let
  latitude1="-27"
  data-daylength=<<e_daylength """<<latitude1>>""">>
/>
  <$htmlwidgets
    type="echarts4r"
    data="""<<data-daylength>>"""
    uuid="htmlwidget-9e88bb152f72bbc8b7f4"
  />
</$let>
1 Like

Thanks. Will try it.