Change the background color depending on the prefix

csshtmlvisualforce

I want to change the background color depending on the prefix….the command I'm trying to use has given a syntax error, where am I going wrong? Or is this idea not possible

<body style="{!if(!$Site.Prefix == '/portalEllas',background: #164E4B,background: #0c4453)}">

Best Answer

In your case, the output must be a string (enclosed in quotes). You also potentially have an extra !; the ! in a merge formula is part of the merge syntax, as in {!...}. Anywhere else besides that, ! acts as the NOT() function. Field names are not ordinarily prefixed with !. If you use it as written, it effectively makes the condition: $Site.Prefix != '/portalEllas', which is probably not what you meant.

<body style="{!if($Site.Prefix == '/portalEllas','background: #164E4B','background: #0c4453')}">

You can optimize this by moving the background out of the formula:

<body style="background: {!if($Site.Prefix == '/portalEllas','#164E4B','#0c4453')}">