They are both controls fetched from the master page. The banner at the top, that works through out the site uses:
lnkTopBanner.NavigateUrl = startPage["TopBannerLInk"] as string ?? string.Empty;
lnkTopBanner.ImageUrl = startPage["TopBanner"] as string ?? string.Empty;
lnkTopBanner.ToolTip = startPage["TopBannerToolTip"] as string ?? string.Empty;
Not the best looking code out there but it gets the job done. The banners on the right hand side are set with:
using System;
using EPiServer.Core;
using EPiServer;
using EPiServer.Filters;
namespace EPiServer.Templates.Public.Units.Static
{
/// <summary>
/// Creates a listing of the side banners.
/// </summary>
public partial class SideBanners : UserControlBase
{
private string _pageLinkProperty;
private string _imageBanner;
private string _flashBanner;
private string _flashHeight;
private string _flashWidth;
protected override void OnLoad(System.EventArgs e)
{
base.OnLoad(e);
PageData startPage = DataFactory.Instance.GetPage(PageReference.StartPage);
imgAddSign.ImageUrl = startPage["AddSign"] as string ?? string.Empty;
imgAddSign.AlternateText = startPage["AddSignAlt"] as string ?? string.Empty;
epiPageList.PageLinkProperty = PageLinkProperty;
epiPageList.Filter += this.epiPageList_Filter;
epiPageList.DataBind();
}
protected void epiPageList_Filter(object sender, FilterEventArgs e)
{
new FilterRandomize().Filter(e.Pages);
}
/// <summary>
/// Gets or sets the name of the page property pointing out the parent page of this page list
/// </summary>
/// <returns>The name of the page property pointing out the parent page.</returns>
public string PageLinkProperty
{
get { return _pageLinkProperty; }
set { _pageLinkProperty = value; }
}
/// <summary>
/// Gets or sets the name of the property pointing out the thumbnail image for the current item in the PageList.
/// </summary>
/// <returns>
/// The name of the property pointing out the thumbnail image for the current item in the PageList.
/// </returns>
public string ImageBanner
{
get { return _imageBanner; }
set { _imageBanner = value; }
}
public string FlashBanner
{
get { return _flashBanner; }
set { _flashBanner = value; }
}
public string FlashHeight
{
get { return _flashHeight; }
set { _flashHeight = value; }
}
public string FlashWidth
{
get { return _flashWidth; }
set { _flashWidth = value; }
}
protected string GetImage(PageData page)
{
if (page[ImageBanner] != null)
{
string _imgTag = "<a href=\"" + page["LinkURL"].ToString() + "\" target=\"_blank\"><img id=\"BannerPicture\" src=\"{0}\" alt=\"{1}\" /></a>";
return string.Format(_imgTag, page[ImageBanner], page.PageName);
}
if (page[FlashBanner] != null)
{
string movieURL = page[FlashBanner].ToString();
string movieHeight = page[FlashHeight].ToString();
string movieWidth = page[FlashWidth].ToString();
string flashCode = "<!--[if !IE]> -->" +
"<object type=\"application/x-shockwave-flash\" data=\"" + movieURL + "\" width=\"" + movieWidth + "\" height=\"" + movieHeight + "\">" +
"<!-- <![endif]-->" +
"<!--[if IE]>" +
"<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"" + movieWidth + "\" height=\"" + movieHeight + "\">" +
"<param name=\"movie\" value=\"" + movieURL + "\" />" +
"<!--><!--dgx-->" +
"<param name=\"loop\" value=\"true\" />" +
"<param name=\"menu\" value=\"false\" />" +
"<p>This is <b>alternative</b> content.</p>" +
"</object>" +
"<!-- <![endif]-->";
return flashCode;
}
return string.Empty;
}
protected string GetNavigationURL(PageData page)
{
return page["LinkURL"].ToString();
}
}
}
The control is working since it renders the background of the div they are in but it just doesn't get the content that's suppose to be inside.
How do you assign the SideBanners.PageLinkProperty in your MasterPage? It seems like it refers to CurrentPage rather than the start page. The reason the banner works is not that the related properties are inherited (only dynamic properties are inherited), but because you explicitly read the properties from the start page (in SideBanners.OnLoad).
You were correct with the fact that it points to current page instead of the start page, but how do I get it to get the property from the start page? I can't seem to find the line to put in. Right now it says
<%# GetImage(GetPage(EPiServer.Core.PageReference.StartPage)) %>
and that doesn't work at all.
I suppose that line sits inside your pagelist (epiPageList)? How is the SideBanners.PageLinkProperty assigned? If it is not set when the pagelist loads you will get nothing.
It's assigned as a property in the start page pagetype then by
<bm:BannersList PageLinkProperty="BannersRoot" Heading=" " runat="server" ImageBanner="ImageURL" FlashBanner="FlashURL" BannerLink="LinkURL" FlashHeight="FlashHeight" FlashWidth="FlashWidth" />
There's where it goes wrong. When the pagelist inside your control loads it will look for the BannersRoot property on the current page. You need to make sure the pagelist uses the startpage as source. One way would be to set the PageLink property rather than the PageLinkProperty property i.e. doing something like
epiPageList.PageLink = (PageReference)(startPage["BannersRoot"] ?? PageReference.EmptyReference);
Excactly, but isn't this line in the markup the line that needs to be changed? How do I change it to read from the start page?
<%# GetImage(Container.CurrentPage) %>
That line should be correct (using Container.CurrentPage). You tell the pagelist to read from the startpage, that means it will go through the children of the start page and list them, and for each item in the list call your GetImage on the pagedata object.
But even when I add epiPageList.PageLink = (PageReference)(startPage["BannersRoot"] ?? PageReference.EmptyReference); it only works on the start page. This is starting to get really confusing... :)
Have you removed PageLinkProperty = "BannersRoot" from the markup? PageLinkProperty takes precedence over PageLink so nothing will change if you have both set. Sorry I forgot to mention this.
I've got some trouble figuring out how to make a proprty on a page inheritable down through the page tree. Here's the scenario:
I'm working on a banner system for our page. It includes a single top banner on the top of the pages and a list of multiple banners on the right hand side of the pages. The top banner is set through a image link-property, by selecting a picture, and the side banners is a page-property pointing to a node in the page tree containing the banners. Both of them are set in the edit mode of the start page.
My problem is that the top banner is showing in all the different pages and page types throughout the site while the side banners only show on the start page. Both of them are in the master page but how come it's only the top banner that is inherited throughout the site?
Best regards