Dynamic Variable Creation

nzblue_fish
nzblue_fish's picture
User offline. Last seen 2 weeks 4 days ago. Offline
Joined: 09/30/2009
Points: 1165

Hi fellow mashers,

Does anyone know if it's possible to dynamically create a variable in an emml script.

For example:

 Some variable that contains a string value:

  <variable name="dynamVar" type="string" default="myVariable" />

then

  <assign literal="a bit of data" outputvariable="{$dynamVar}" />

resulting in:

  <display message="myVariable contains:" variable="myVariable" />

producing:

 myVariable contains: a bit of data

I've tried a few things, but will find another approach to the problem I have if this isn't possible.

Cheers, Innes

0
Your rating: None
smitchell
smitchell's picture
User offline. Last seen 15 hours 36 min ago. Offline
Joined: 08/29/2008
Points: 34

You can dynamically assign the value of a variable in EMML, using the <template> statement. If you're not familiar with <template>, you can find documentation on <template> at http://www.jackbe.com/prestodocs/v2.7.0/index.html. Then search for "template". The topics on Dynamic Strings and Creating Generic Mashup Scripts are probably the most appropriate.

If that doesn't give you what you need, take a look at using EMML to generate an EMML mashup script dynamically and then execute it within the parent EMML. The topic on Generating Mashup Scripts Dynamically in the docs covers this possibility.

Hope this helps

 

<!--Session data-->

 

Sara, technical writer/jackbe

 

nzblue_fish
nzblue_fish's picture
User offline. Last seen 2 weeks 4 days ago. Offline
Joined: 09/30/2009
Points: 1165

Hi Sara,

thanks for the reply. I took a look at <template> but can't quite see how to use it to do what I want.

Here's what I'm trying to do: create a variable 'myVariable' that contains the value 'abcd' from the contents of two other variables, one that contains the variable name and the other that contains the variable content.

e.g. varName="myVariable" and  varContent="abcb"  used to create to $myVariable="abcd"

Cheers, Innes

smitchell
smitchell's picture
User offline. Last seen 15 hours 36 min ago. Offline
Joined: 08/29/2008
Points: 34

I'm trying to confirm, Innes, but I believe that variable names cannot be assigned dynamically. What you can do, instead, is use my second suggestion. Basically, write an EMML that writes the EMML with your dynamic varriable name defined statically and then execute that built EMML.

<!--Session data-->

 

Sara, technical writer/jackbe

 

nzblue_fish
nzblue_fish's picture
User offline. Last seen 2 weeks 4 days ago. Offline
Joined: 09/30/2009
Points: 1165

Thanks Sara,

I've been thinking about your second suggestion, but I' not sure how you would execute the dynamically created EMML?

Cheers, Innes

smitchell
smitchell's picture
User offline. Last seen 15 hours 36 min ago. Offline
Joined: 08/29/2008
Points: 34

Look at the doc topic I pointed out previously. It uses a built-in macro. So you build the EMML as a string and then pass that to the macro to execute.

<!--Session data-->

 

Sara, technical writer/jackbe