Page 1 of 1

IF VAR [contains] "STRING" ?

PostPosted: Wed Mar 14, 2012 1:53 pm
by nsd999
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

Re: IF VAR [contains] "STRING" ?

PostPosted: Wed Mar 14, 2012 9:15 pm
by Jim
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.

Re: IF VAR [contains] "STRING" ?

PostPosted: Wed Mar 14, 2012 10:47 pm
by nsd999
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

Re: IF VAR [contains] "STRING" ?

PostPosted: Wed Mar 14, 2012 11:39 pm
by Jim
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 --]

Re: IF VAR [contains] "STRING" ?

PostPosted: Thu Mar 15, 2012 8:33 am
by nsd999
Hi Jim,

Thanks for the help! That worked like a charm.

Best,
Joe