Variable Replacement Script

Using Catfish MegaEdit you can create text fields which use forms to replace variables which allows for a more user-friendly input process.

To start, you need to create a dynamic product, this article will explain how to do this.

Once you have your product created, you will need to navigate to Catfish -> Infigo Variable Data -> Dynamic Product Settings and make sure that ScriptingEnabled is checked.



Once you have made sure that ScriptingEnabled is turned you, navigate to Catfish -> Infigo Variable Data -> Dynamic Products -> Scripts as seen in the screenshots below.


Here you want to enable the Variable Replacement hardcoded script by clicking on the checkbox beside it and clicking Save.


Now that the script is enabled, you need to navigate to Catfish -> Infigo Variable Data -> Dynamic Products and click "Edit" beside your dynamic product. Once here, you need to navigate to the Scripts tab, find Variable Replacement in the script list and enable it by double-clicking on the checkbox beside it and clicking the green tick.


In the same section you'll find the Config column to the right of the Order column, the order column being visible in the screenshot above. In order for the script to work properly, you need to copy and paste the code below into the Config column of the Variable Replacement row.

VariableTag: "form-ph",
Placeholder: {
Start: "[++",
End: "++]"
Mode: "UI",
SelectArea: {
NormalFormat: {
fill: "",
stroke: ""
HoverFormat: {
fill: "rgba(255, 255, 0, 0.2)",
stroke: "black"
TextAreas: ["Footer", "Body"],
ProportionalScaling: {
SeparatorRegExp: "\s*:\s*",
MaxFontSize: 40,
MinFontSize: 20,
Tag: "form-ps"
CombineTag: "form-region-"

Your Variable Replacement config column should now look like the screenshot below.


Now you'll need to find your dynamic product on your storefront and open it in megaedit (make sure you're still signed in as a storefront admin).

Create a text field and increase the size to fit the page (this is for demonstration purposes, the text field can be any size)

For the same text field, navigate to the Details tab of the Text Options popup (the far right tab) and find the Tags field. In this field, type in "form-ph" without the "s then type the following lines in the text field itself:




This is what you should end up with:


Still in MegaEdit, navigate to Show Menu -> Admin Links and click on Save as product default. Once this is done, the script will be set up and an easy way to test this is to open an incognito/private window and navigate to your product without signing in, which is the method I will be using, however signing out of your account and navigating there will also work.

Once you've found your product, open it in megaedit and you will be face with a nearly identical screen, however if you hover your mouse over the field you made you'll see it become highlighted in yellow. Clicking on this field will open the below form which allows you to edit the field itself.


Anything you put in the fields will replace the respective variable placeholders as soon as you hit OK. For example, if you put "This replaces the header" in the Header box and click OK, the text field will change to what is in the screenshot below.


[++Header++] was replaced with the text given in the Header field while both [++Body++] and [++Footer++] were replaced with what was in the Body and Footer fields, which in this instance is nothing.


Returning to the config that was pasted in earlier, there are a lot of customisation options which can be controlled by editing different parts of it. 



This is the tag you use to assign text fields which you want to be affected by this script. Whatever you put in the quotation on this line will be used as the tag.


You may have noticed that when you were filling out the text field in megaedit the fields which were replaced started with [++ and ended with ++]. This is because these are what is used to define placeholders (placeholders being the fields which get replaced through the use of the form. You can change these to whatever you want by changing what's in the quotation marks, for example you could have your placeholders be define by surround them with < and > or even PlaceholderStart and PlaceholderEnd.


There are four separate modes available to this script. You can change which mode the script runs by filling the quotation marks on this line with one of the following names:

UI - This is the default mode and will produce the form shown previously in this article.

No Ui - This disables the form and allows the field to be edited as if it were a regular text field, however the placeholders will still be there.

UI with opt out - This option adds a third button to the form; Dismiss Dialog. When this is pressed, the form will disappear and won't re-appear until the webpage is refreshed, allowing the user to click on the field and edit it without the usage of the form

Sidebar - This allows the user to manually edit the text field as they would without the use of the form, however a sidebar appears on the right of the screen which can be used to edit the placeholders directly.


The placeholders used in this example aren't fixed, you can add or remove placeholders as you see fit using this section of the config. For example, if you wanted to add a field named "Limb" you would need to change what's in the square brackets from [ "Footer", "Body" ] to [ "Footer", "Body", "Limb" ]. Note: In order to make use of this new variable, you will need to put a placeholder with the appropriate syntax around it in your text field I.E. [++Limb++]


The text input from the form will try and automatically scale to fit the text given on the page better, however it is possible to limit this using this setting. You can set a minimum font size and a maximum font size which the scaling will have to obey.

You can also manually set a factor for each field to scale to when you are inserting the placeholder variables into the megaedit field by using the format [++Placeholder:Factor++]. For example, to increase the size of the header by 50% you would need to write [++Header:1.5++] in the text field instead of [++Header++]. This will still obey the minimum and maximum sizes you have set however.


Have more questions? Submit a request


Article is closed for comments.
Powered by Zendesk