Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > IFCompare question View modes: 
User avatar
Member
Member
wsutton - 8/28/2013 4:05:58 PM
   
IFCompare question
In this statement Homepage_bannerID is an int. Does this statement evaluate Homepage_bannerID and then output the string "Watch Video" or "Find Out More"?

<a href="<%# Eval("Homepage_link")%>" class="wp-banner"><%# IFCompare(Eval("Homepage_bannerID"), 31, "Watch Video", "Find Out More") %> </a>

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 8/29/2013 7:45:02 AM
   
RE:IFCompare question
Methods are case sensitive, looks like you have IF vs. If. Also you should use the built-in Eval<string>() methods to convert the object value to a return type for your comparison. Your statement should read like this
IfCompare(EvalInteger("Homepage_bannerID"), 31, "Watch Video", "Find Out More") 

User avatar
Member
Member
wsutton - 8/29/2013 1:37:08 PM
   
RE:IFCompare question
This worked, thanks. While working on this I was wondering, how do you declare a codebehind in a transformation? Because, if statements and methods really should be put in a codebehind file.

User avatar
Kentico Legend
Kentico Legend
Accepted solutionAccepted solution
Brenden Kehren - 8/29/2013 1:53:09 PM
   
RE:IFCompare question
wsutton wrote: While working on this I was wondering, how do you declare a codebehind in a transformation?
Unless you are checking the files out to the file system OR using ASPX method of building your website, you don't.
wsutton wrote: Because, if statements and methods really should be put in a codebehind file.
If you want to get technical, yes it's a best practice. Now keep in mind how the Portal Development works. You can build a whole site (10 pages or 10,000 pages) all within the UI without ever touching any physical code behind files by using this method. This is the beauty and ease of working with Kentico.

Transformations are really the connection a developer has between a webpart and code behind without having to touch any physical code behind files. There are many posts on this forum and if you look through the code enough you'll find many times where Kentico actually places lots of code behind worthy syntax in a transformation.

If I were you, I wouldn't get hung up on it. Take advantage of the ease of use. If you find yourself doing something all the time in a transformation, by all means create a custom class and method for it, then call it in your transformation. These files would go in your App_Code directory. Take a look here for best practice on file/folder structure.

Good luck!
Brenden