Product description & variables

elvis's picture

Since I had only t-shirts in my shop I had the same text on each product page explaining the measures (width, sleeve length, length) and I also used open field variables for particular item's different measures: open field 1 was size S width, open field 2 was size S sleeve etc. There is a html table for this. Here is the screenshot.

Now I have added footwear to my shop. So sleeve length doesn't really matter for footwear.

How could I achieve this:

if the product is t-shirt, display text regarding t-shirts & measures using variables (as shown on the screenshot above); if the product is footwear, show nothing in there; if it is some other gadget, display product info 1 etc.


This can be a little tough,

This can be a little tough, but I have done this kind of thing on another site...

*****************************************************************
<script type="text/javascript">
if ("$group_name$" == "Your Product Group Name"){
document.write("Write your html code in here, replace double quotes with single quotes")
}
else{
document.write("Write your html code in here, replace double quotes with single quotes")
}
</script>
*****************************************************************

Just change "Your Product Group Name" with the name of the group that does not want the table of sizes and add the HTML code to display the info about the shoes...

The Document.write section after the "Else" will be executed if the $group_name$ parameter does not match "Your Product Group Name".

If you add several groups, it can be messy, the code below will check for 3 specific group names, if all three do not match then it will execute the last section after the Else...

*****************************************************************
<script type="text/javascript">
if ("$group_name$" == "Your Product Group Name"){
document.write("Write your html code in here, replace double quotes with single quotes")
}
else if ("$group_name$" == "Your Product Group Name2"){
document.write("Write your html code in here, replace double quotes with single quotes")
}
else if ("$group_name$" == "Your Product Group Name3"){
document.write("Write your html code in here, replace double quotes with single quotes")
}
else{
document.write("Write your html code in here, replace double quotes with single quotes")
}
</script>
*****************************************************************

If you want to display the same code per group, you can use this code...

<script type="text/javascript">
if ("$group_name$" == "Your Product Group Name" || "$group_name$" == "Your Product Group Name2" || "$group_name$" == "Your Product Group Name3" ){
document.write("Write your html code in here, replace double quotes with single quotes")
}
else{
document.write("Write your html code in here, replace double quotes with single quotes")
}
</script>
*****************************************************************

Those two lines mean "OR" and are called PIPES (left of the 'Z' key on my keyboard)

Thank you so much,

elvis's picture

it seems to work as long I write a word or two in document.write. It displays nothing if I put html code in there. Changed the single quotes into double ones too. I should not change the double quotes inside the html but javascript, right?

You may have to use double

You may have to use double quotes for the document.write and single for the html code inside...

document.write("<a href='index.html' target='_blank'>Link to index page</a>")

I think you can swap the quotes over to use single in the document.write and double inside but I've not tested it...

document.write('<a href="index.html" target="_blank">Link to index page</a>')

It's not the quotes

elvis's picture

there should be no spaces between tags, instead of

<*tr>
<*td >
<*div>
<*span>

it should be like

<*tr><*td ><*div><*span>

and then it works.