2👍
✅
Why not do it in the template language?
<input type="checkbox" {% if node.id in selected_ids %} checked="checked"{% endif %} id="{{ node.id }}" value="{{ node.id }}" name="category"/>
Source:stackexchange.com