I want to have the option of displaying an image instead of this flashbanner on certain pages so I created the following XSLT but I get an XSLT error when I try to put it on my page. I assume I need to wrap the code above in something to put it in my XSLT but I don't know what, can someone please help. The whole XSLT I have so far is as follows:
Thanks for the response Dan, it no longer shows an XSLT error and it does show an alternative image if I select one but it doesn't show the flash banner on pages where I haven't selected an alternative image, I have check the source code and it is just outputing the code from the XSLT as opposed to executing it as such, any ideas why it is doing this and what I can do to resolve it? This is the output source from my XSLT:
The "<cc2:CAdRotator />" tag is a .NET control - you wont be able to execute it in the XSLT, (as it is called too late in the ASP.NET Page Lifecycle).
What you need to do is use the same logic in a .NET user-control. Where you would hide the "<cc2:CAdRotator Visible="false" />" - then check if the property ("topbannerimage" from the current page), has a value ... if so, then use an <asp:Image /> control to display the image ... otherwise set the "CAdRotator" to visible.
In a nutshell, you're going down the wrong route trying to do this in XSLT.
This isn't tested in any form, but here's an example .NET user-control you can try:
<%@ Control Language="C#" %>
<%@ Register TagPrefix="cc2" TagName="CAdRotator" Src="~/CAdRotator.ascx" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Int32 mediaId = 0;
// get the 'topbannerimage' media id
String topBannerNodeId = umbraco.library.GetItem("topbannerimage");
// try to parse the media id
if (Int32.TryParse(topBannerNodeId, out mediaId))
{
// get the media item
umbraco.cms.businesslogic.media.Media topBanner = new umbraco.cms.businesslogic.media.Media(mediaId);
// check if that media item is not null
if (topBanner != null)
{
// set the properties of the image
this.Image1.ImageUrl = topBanner.getProperty("umbracoFile").Value.ToString();
this.Image1.Width = new Unit(topBanner.getProperty("umbracoWidth").Value.ToString());
this.Image1.Height = new Unit(topBanner.getProperty("umbracoHeight").Value.ToString());
// set the image to visible
this.Image1.Visible = true;
// hide the ad rotator
this.CAdRotator1.Visible = false;
}
else
{
// hide the image
this.Image1.Visible = false;
// show the ad rotator
this.CAdRotator1.Visible = true;
}
}
}
</script>
<asp:Image runat="server" ID="Image1" Visible="false" />
<cc2:CAdRotator runat="server" ID="CAdRotator1" AdvertisementFile="/App_Data/FlashTop.xml" Visible="false" />
It might look overly complicated ... but the logic is similar to what you are trying to achieve in the XSLT.
Obviously, you'll need to change the reference to the CAdRotator control.
Thanks for this, I spent 2 hours today trying to work out just how to display an image from an Umbraco property using asp.net but the closest I got was displaying the node ID! As I said before my asp.net stills are none existant. I now have the following code taken from what you wrote above with a couple of small modifications but I cannot seem to get it to display the adrotator, if I change the visibilty of the ad rotator to true then it will display (all the time regardless of whether there is a topbannerimage) but it seems that for some reason the else statement that tells the adrotator to change visibility to true is not being picked up, any ideas why this would be?
Thanks for the quick response, I have tried what you said and now have the following code but it is still behaving exactly the same, it's almost as if it's not running the else command:
I think a little debugging is needed. Let's see what's in the "mediaId" ...
After the "if (Int32.TryParse(topBannerNodeId, out mediaId))" ... add a "Response.Write( mediaId.ToString() );"
Depending on what the value is, we may need to add another condition ... like "if (mediaId > 0)" ... as I have a sneaky feeling that "new Media( mediaId ) isn't returning null. But it's difficult to tell without further debugging.
Thanks again for the quick response, I have added that line in underneath the line you said "if (int32..........." and on the page that does have a topbannerimage it is displaying the ID of that image but on a page that doesn't have a topbannerimage there is the following error page, have I put it in the wrong place or should I have removed something else when adding it?:
Server Error in '/' Application.
No node exists with id '0'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: No node exists with id '0'
I tried what you said above but it still didn't work, I had the same issue, showed the topbannerimage if there was one but showed nothing on other pages, I have managed to get it to work with the following code which I am happy to leave it like this as long as you can't see any issues with doing it this way (as I said before not really up on my asp.net so don't know if this is best practice or not). Not sure if this helps explain what the problem was with the original code? As you can see I have changed the visibility of the adrotator to true, then added into the if statement to make its visibilty false if topbanner isn't null, I then completely removed the Else statement because I don't seem to need it. Let me know what you think:
// get the 'topbannerimage' media id String topBannerNodeId = umbraco.library.GetItem("topbannerimage");
// try to parse the media id if (Int32.TryParse(topBannerNodeId, out mediaId))
{ // get the media item umbraco.cms.businesslogic.media.Media topBanner = new umbraco.cms.businesslogic.media.Media(mediaId);
// check if that media item is not null if (topBanner != null) { // set the properties of the image this.Image1.ImageUrl = topBanner.getProperty("umbracoFile").Value.ToString(); this.Image1.Width = new Unit(topBanner.getProperty("umbracoWidth").Value.ToString()); this.Image1.Height = new Unit(topBanner.getProperty("umbracoHeight").Value.ToString());
// set the image to visible this.Image1.Visible = true;
// hide the ad rotator this.CAdRotator1.Visible = false;
Moving ad rotator into XSLT code
Hi, I have an Umbraco V4 website that currently has a top banner that is shown using the following code in the master template:
I want to have the option of displaying an image instead of this flashbanner on certain pages so I created the following XSLT but I get an XSLT error when I try to put it on my page. I assume I need to wrap the code above in something to put it in my XSLT but I don't know what, can someone please help. The whole XSLT I have so far is as follows:
Perhaps it's a namespace issue?
You may need to add something like
Dan
Thanks for the response Dan, it no longer shows an XSLT error and it does show an alternative image if I select one but it doesn't show the flash banner on pages where I haven't selected an alternative image, I have check the source code and it is just outputing the code from the XSLT as opposed to executing it as such, any ideas why it is doing this and what I can do to resolve it? This is the output source from my XSLT:
<cc2:CAdRotator id="CAdRotator1" runat="server" AdvertisementFile="/App_Data/FlashTop.xml" xmlns:cc2="urn:CAdRotator:xslt" />
And this is what gets outputted when I don't use the XSLT and just have the CAdRotator directly in the page:
Anyone got any ideas?
The "<cc2:CAdRotator />" tag is a .NET control - you wont be able to execute it in the XSLT, (as it is called too late in the ASP.NET Page Lifecycle).
What you need to do is use the same logic in a .NET user-control. Where you would hide the "<cc2:CAdRotator Visible="false" />" - then check if the property ("topbannerimage" from the current page), has a value ... if so, then use an <asp:Image /> control to display the image ... otherwise set the "CAdRotator" to visible.
In a nutshell, you're going down the wrong route trying to do this in XSLT.
Cheers, Lee.
Thanks for the response Lee, hmmm that's not good news for me because the reason I was trying to use XSLT is because I do not know asp.net very well.
Depending on the complexity of the ad rotator, this could potentially be managed in umbraco as well?
Tony,
This isn't tested in any form, but here's an example .NET user-control you can try:
It might look overly complicated ... but the logic is similar to what you are trying to achieve in the XSLT.
Obviously, you'll need to change the reference to the CAdRotator control.
Good luck!
Cheers, Lee.
Hi Lee,
Thanks for this, I spent 2 hours today trying to work out just how to display an image from an Umbraco property using asp.net but the closest I got was displaying the node ID! As I said before my asp.net stills are none existant. I now have the following code taken from what you wrote above with a couple of small modifications but I cannot seem to get it to display the adrotator, if I change the visibilty of the ad rotator to true then it will display (all the time regardless of whether there is a topbannerimage) but it seems that for some reason the else statement that tells the adrotator to change visibility to true is not being picked up, any ideas why this would be?
Hmmm... that sounds like strange behaviour of the CAdRotator control.
I suggest that you wrap an <asp:Placeholder> around the CAdRotator tag and set the Visibility of that instead.
Let me know if you need further explanation.
Hi Lee,
Thanks for the quick response, I have tried what you said and now have the following code but it is still behaving exactly the same, it's almost as if it's not running the else command:
Hi Tony,
I think a little debugging is needed. Let's see what's in the "mediaId" ...
After the "if (Int32.TryParse(topBannerNodeId, out mediaId))" ... add a "Response.Write( mediaId.ToString() );"
Depending on what the value is, we may need to add another condition ... like "if (mediaId > 0)" ... as I have a sneaky feeling that "new Media( mediaId ) isn't returning null. But it's difficult to tell without further debugging.
Cheers, Lee.
Thanks again for the quick response, I have added that line in underneath the line you said "if (int32..........." and on the page that does have a topbannerimage it is displaying the ID of that image but on a page that doesn't have a topbannerimage there is the following error page, have I put it in the wrong place or should I have removed something else when adding it?:
Server Error in '/' Application.
No node exists with id '0'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: No node exists with id '0'
Try changing the condition from:
to:
See if that works?
Hi Lee,
I tried what you said above but it still didn't work, I had the same issue, showed the topbannerimage if there was one but showed nothing on other pages, I have managed to get it to work with the following code which I am happy to leave it like this as long as you can't see any issues with doing it this way (as I said before not really up on my asp.net so don't know if this is best practice or not). Not sure if this helps explain what the problem was with the original code? As you can see I have changed the visibility of the adrotator to true, then added into the if statement to make its visibilty false if topbanner isn't null, I then completely removed the Else statement because I don't seem to need it. Let me know what you think:
Hi Tony, if it works - that's great! Glad it's working for you now.
(remember to mark the solution - or at least spread some karma / thumbs-up!) :-D
Cheers, Lee.
is working on a reply...