extension class for news template

Vote:
 

Hello!

Im new to EPiserver.

I´m trying to write a news template. I am following <a href="http://www.frederikvig.com/2009/07/episerver-web-controls-newslist">Fredrik Vigs guide on how to manage newslist templates</a>

The problem is that he is using some sort of extension class for some of his functions. I am trying to print out some page properties using this code in the newslist template: Container.CurrentPage.GetTitle();

For this to work I am trying to write an extension class file with the GetTitle method, but I cant get it to work..

 

using EPiServer.Core;

namespace Qwerty.Extensions.Classes
{
    public partial class News : PageData
    {
        public static string GetTitle(this PageData pageData)
        {
            string text = pageData["Title"] as string;
            return text;
        }
    }
}

 

I get this error in my newspage template: "Extension methods must be defined in a non-generic static class"

and the same error in my news extension class.

 

please help! :)

#51880
Jun 27, 2011 17:14
Vote:
 

Hi Mathias!

You need to move your eztension method into a static class, something like this:

public static class NewsExtension
{
   public static string GetTitle(this PageData pageData)
   {
       return pageData["Title"] as string
   }
}

/johan

#51882
Jun 27, 2011 17:29
Vote:
 

Yes I tried that but I got this weird error "Extension methods must be defined in a non-generic static classy"

But I solved it. It was because my code behind had the same method GetTitle as my extension class. That is apperently not allowed? :P

 

Thanks!

#51892
Jun 28, 2011 8:45
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.