Created
October 31, 2014 18:36
-
-
Save Jeavon/0411ca45e20d1c42ec84 to your computer and use it in GitHub Desktop.
Wrapper for GetCropUrl to set default bgColor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MyStuff.App_Code | |
{ | |
using Umbraco.Core.Models; | |
using Umbraco.Web; | |
public static class MyHelpers | |
{ | |
public static string MyGetCropUrl(this IPublishedContent publishedContent, int width, int height) | |
{ | |
var bgColor = "fff"; | |
return publishedContent.GetCropUrl(width, height, furtherOptions: string.Format("&bgcolor={0}", bgColor)); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@inherits UmbracoTemplatePage | |
@{ | |
var a = Model.Content.MyGetCropUrl(100, 100); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<system.web.webPages.razor> | |
<pages pageBaseType="System.Web.Mvc.WebViewPage"> | |
<namespaces> | |
<add namespace="System.Web.Mvc" /> | |
<add namespace="System.Web.Mvc.Ajax" /> | |
<add namespace="System.Web.Mvc.Html" /> | |
<add namespace="System.Web.Routing" /> | |
<add namespace="Umbraco.Web" /> | |
<add namespace="Umbraco.Core" /> | |
<add namespace="Umbraco.Core.Models" /> | |
<add namespace="Umbraco.Web.Mvc" /> | |
<add namespace="Microsoft.Web.Helpers" /> | |
<add namespace="umbraco" /> | |
<add namespace="Examine" /> | |
<add namespace="MyStuff.App_Code" /> | |
</namespaces> | |
</pages> | |
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> | |
</system.web.webPages.razor> | |
No problem.
That would be a string extension method which you could do but why when you already have the IPublishedContent object?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Jeavon
Thanks a million for this. Learned something new about views/web.config too!
So if i do Model.Content.MyGetCropURL(width.height) it returns something like;
/settings/?mode=pad&width=100&height=100&bgcolor=fff&rnd=130547015430000000
where the page is settings.
If I wanna do this on a image url like Umbraco.Media(id).Url?.. or Umbraco.TypedMedia(id).Url? how should I call it?
many thanks for taking time to put this together!