Sub Expressions in handlebar Varriables

I am trying to get some subexpressions to work in mind studio. Here is why.

I have these two variables that are resolving correctly:

  • Blog Title: {{get contentPlan “$.brandPosts[0].title”}}
  • Focus: {{get contentPlan “$.brandPosts[0].focus”}}

These variables are in a part of the workflow that will get re-run a few times. For each time it reruns, I need the [0] to increase one intertager. This is so that it pulls the next data point in the array.

I am trying to pull from an array that is named “initVars” that counts the number of blogs that are created. My thinking is that I can pull that increased number into the [0] part so that it pulls each new data point for each time it runs through,

When I incorporate subexpressions in my handlebar variable, it stops resolving for almost all of them. I am not sure what to really do here.

2 Likes

I think you might be pushing the limits of handlebars a bit there :sweat_smile:

If I were you, I would look into creating a simple custom function in the preceding step that sets an intermediary variable for the current iteration. So you could have a function that is just like:

const currentIndex = initVars.length; // or however you are computing which post you are on
ai.vars.currentPost = ai.vars.contentPlan.brandPosts[currentIndex];

And then in the block you could just do {{get currentPost "$.title"}}.

You might also want to consider using the Run Workflow block in array mode, which would have the added benefit of allowing you to run all of these in parallel (much faster!).

Hope this helps!

2 Likes

Thank You Sean,
I do set something earlier in the workflow that sets what you described. It looks like this:

Array Name: initVars
Structure:
{
“usedKeywords”: ,
“generatedBlogs”: ,
“currentBlogIndex”: 0,
“currentBlogType”: “brand”
}

I will work on what you recommended there! Thank you so much!

You can add in handlebars, assuming your variable is an integer - {{add yourVar integerToAdd}}. I discovered the new iterate function when running a child workflow, must say it’s a massive upgrade. Mindstudio has really stepped up their game and become much more useful for me.

1 Like

Is that for an array of nested json objects? I.e. are those four keys supposed to be repeated in a json output? If so, I’d try:

{
“initVars”: [{
“usedKeywords”: [“string”],
“generatedBlogs”: [“string”],
“currentBlogIndex”: 0,
“currentBlogType”: “brand”
}]
}

…if you want an array to use, still need to set the vars by getting values from the json when it’s populated.