IF VAR [contains] "STRING" ?

Questions and answers about ShopSite Custom Templates

IF VAR [contains] "STRING" ?

Postby nsd999 » Wed Mar 14, 2012 1:53 pm

Hi guys,

I'm trying to build the following expression but don't know exactly how:

IF Page.Name CONTAINS "Match"

Any help is appreciated. Basically I want to choose between two different free shipping images depending upon which page we're at.

Thanks,
Joe
nsd999
 
Posts: 17
Joined: Thu May 05, 2011 12:05 pm

Re: IF VAR [contains] "STRING" ?

Postby Jim » Wed Mar 14, 2012 9:15 pm

It must be an exact match not just contain the word and I believe that it it a case sensitive match..

[-- IF Page.Name "Does This Match" --] will only be true if the page name field contains "Does This Match". It will be false if it contained "This Does Match" So you must be very explicit in what you put in the field you are trying to match. Note that in some cases you can use the IF statement without a value for example [-- If Page.Name --} will return true if any value is in the page name field.

The easiest way to test something like this is to create a simple page template with the minimum html required for a page and then insert the tag you are wanting to use and see what is returned in various situations.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Re: IF VAR [contains] "STRING" ?

Postby nsd999 » Wed Mar 14, 2012 10:47 pm

Hi Jim,

Thanks for the reply.

Does that work on partial matches?

I need to do something like this:

Code: Select all
[-- IF VAR.PageName "Match" --]
     <img src="[-- VAR.ImagePath --]/media/freeShippingOnMatch.jpg" alt="Free Shipping Information" style="width:300px; height:57px; border:none;" ></a>
[-- ELSE --]
     <img src="[-- VAR.ImagePath --]/media/freeshipping.jpg" alt="Free Shipping Information" style="width:300px; height:57px; border:none;" ></a>
[-- END_IF --]             

And VAR.PageName can be things like:

Home
Match Pewter
Match Pewter - Bowl Collection
Match Pewter - Flatware & Serving Pieces Collection
etc..

If this approach won't work, do you have any ideas how I can make this happen?

Thanks,
Joe
nsd999
 
Posts: 17
Joined: Thu May 05, 2011 12:05 pm

Re: IF VAR [contains] "STRING" ?

Postby Jim » Wed Mar 14, 2012 11:39 pm

It won't work on a partial match, it must match the entire text.

The best thing to do is to use one of the extra page fields to indicate what you want to display on that page. Then you can use a single word or couple of words that will match. For example you could use the extra page field 1 and put "Match" in it if you want one image and put "NO" or leave it blank if you want a different image . Then you would code it like this.
Code: Select all
[-- IF Page.field1 "Match" --]
     <img src="[-- VAR.ImagePath --]/media/freeShippingOnMatch.jpg" alt="Free Shipping Information" style="width:300px; height:57px; border:none;" ></a>
[-- ELSE --]
     <img src="[-- VAR.ImagePath --]/media/freeshipping.jpg" alt="Free Shipping Information" style="width:300px; height:57px; border:none;" ></a>
[-- END_IF --]
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Re: IF VAR [contains] "STRING" ?

Postby nsd999 » Thu Mar 15, 2012 8:33 am

Hi Jim,

Thanks for the help! That worked like a charm.

Best,
Joe
nsd999
 
Posts: 17
Joined: Thu May 05, 2011 12:05 pm


Return to Custom Template Questions

Who is online

Users browsing this forum: No registered users and 7 guests