Skip to content

Instantly share code, notes, and snippets.

@Jeavon
Created October 31, 2014 18:36
Show Gist options
  • Save Jeavon/0411ca45e20d1c42ec84 to your computer and use it in GitHub Desktop.
Save Jeavon/0411ca45e20d1c42ec84 to your computer and use it in GitHub Desktop.
Wrapper for GetCropUrl to set default bgColor
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));
}
}
}
@inherits UmbracoTemplatePage
@{
var a = Model.Content.MyGetCropUrl(100, 100);
}
<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>
@Jeavon
Copy link
Author

Jeavon commented Oct 31, 2014

Please note that the web.config snippet is from /Views/Web.config

@akeilox
Copy link

akeilox commented Oct 31, 2014

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!

@Jeavon
Copy link
Author

Jeavon commented Oct 31, 2014

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