Creating nodes dynamically

Hello there,

I am quite new at GoJs, and I am currently running a Palette and a Diagram very similar to Data Flow sample → Data Flow Diagram.
I managed to create nodes, links and adding those to both my Palette and Diagram.
Now, I come to a point where I want to let the user create a custom node himself, based on his desired layout.

For instance,
Number of columns
Number of rows
Number of inports/outports
Does node include picture?

This is more a javascript implementation type question than GoJs but I am wondering how to construct a Node depending on those layout parameters.

I thought of something like this,

function createWidget(typename, rows, columns, hasPicture, picturePath, w, maxports, background, inports, outports){
    var node = $(go.Node, "Spot",
    $(go.Panel, "Auto",
         for(var i;i<columns;i++) $.(go.TextBlock, "Name :", {row : 1, column: i}

And then once this node is being created, just call

addNodeData(nodedata)

To add it to the diagram/palette.
I am quite stuck at this point…

Call the makeTemplate function, then add an instance of the new template name category data object to the Palette.model. This assumes both the Palette and main Diagram are sharing a nodeTemplateMap to which you have added the new template.

I must have been unclear of what I am trying to achieve here.
I understand the mechanism of makeTemplate > adding to created template to templateMap.

What I am struggling with is, making

makeTemplate

itself dynamic, so I can call the function with parameters like number of columns and rows, and create GraphObjects such as Panel, TextBlocks, Picture according to the layout passed in parameters.
For example, let’s say I want 2 rows, 2 columns type layout, I want makeTemplate to create 4 TextBlocks and so forth…

You can dynamically construct a node template, then add it to the template map and the palette’s model. Here’s a codepen with an example:

Your templates will probably end up more complicated than what’s there, but it shows the basic idea.

I didn’t think about decomposing GraphObject creation and then store them into variables, thank you very much!