Our Editors in EPiserver would like to be able to modify the hreflang links of each page as needed. So I would like to modify our pages and enable an override of the default hreflang feature in episerver.
I have started by trying to write my own htmlhelper that will put together the hreflang for me so that I can modify it later.
In the file HtmlHelpers.cs I have started with the following:
public static IHtmlString HrefLangLinks()
{
var pageLanguagesBranches = ContentRepository.GetLanguageBranches<PageData>(ICurrentPage.ContentLink).ToList();
var availablePageLanguages = FilterForVisitor.Filter(pageLanguagesBranches).OfType<PageData>();
// Dictionary<String, String>
return null;
}
Visual Studio is informing me that ICurrentPage
does not have a definition for ContentLink
.
I would appreciate any help as I am not that familiar with EPiserver.
Update 1:
The following was suggested:
public static IHtmlString HrefLangLinks(this BasePage currentPage)
{
var pageLanguagesBranches = ContentRepository.GetLanguageBranches<PageData>(currentPage.ContentLink).ToList();
var availablePageLanguages = FilterForVisitor.Filter(pageLanguagesBranches).OfType<PageData>();
// Dictionary<String, String>
return null;
}
Instead of BasePage
We have StandardPage
which inherits from SitePageData
which inherits from PageData
. I tried all three but that didn't work, Visual Studio underlines this section ContentRepository.GetLanguageBranches<PageData>
with the following message:
Unsupported internal API....
An object reference is required for the non-static field, method or property
ContentRepository.GetLanguageBranches<PageData>(ContentReference)
If you have the consept of a BasePage (you should) that all your pages inherit from, you can try the following:
public static IHtmlString HrefLangLinks(this BasePage currentPage)
{
IContentRepository repo = ServiceLocator.Current.GetInstance<IContentRepository>();
var pageLanguagesBranches = repo.GetLanguageBranches<PageData>(currentPage.ContentLink).ToList();
var availablePageLanguages = FilterForVisitor.Filter(pageLanguagesBranches).OfType<PageData>();
// Dictionary<String, String>
return null;
}