Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
{{ list=plugin_function 'HomeSeerSamplePlugin' 'MyCustomFunctionArray' ['1'] }}
Custom function array values:<br>
{{ for item in list }}
	Item: {{item}}<br>
{{ end }}


If you want to  use your own class as the returned type, you need to make it Serializable:

Code Block
languagec#
C#
[Serializable]
public class TriggerOptionItem 
{
	public int Id { get; set; }
	public string Name { get; set; }

	public TriggerOptionItem(int id, string name) {
		Id = id;
		Name = name;
	}

	public TriggerOptionItem() { }
}

public List<TriggerOptionItem> GetTriggerOption(int numTriggerOptions) 
{
	var triggerOptions = new List<TriggerOptionItem>();
	for (var i = 1; i <= numTriggerOptions; i++) 
	{
		triggerOptions.Add(new TriggerOptionItem(i, $"Trigger Option {i}"));
	}
	return triggerOptions;
}

To use the properties of your class in your html file:

Code Block
languagexml
{{ list2=plugin_function 'HomeSeerSamplePlugin' 'GetTriggerOption' [2] }}
{{ for item in list2 }}
<div class="jui-view jui-toggle">
	<label class="jui-toggle-text" for="{{ item.id }}">{{ item.name }}</label>
	<span class="jui-toggle-control"><span class="form-check form-check-inline jui-toggle-checkbox"><input type="checkbox" class="form-check-input jui-input" id="{{ item.id }}"/> <label class="form-check-label jui-toggle-checkbox-label" for="{{ item.id }}"></label></span></span>
</div>
{{ end }}


Note

The definition of the serializable class needs to be in the plugin exe, located in the HS root folder.