if (!string.IsNullOrEmpty(@node.imageID.ToString()))
{
var mediaItem = Library.MediaById(node.imageID);
var imageCrops = JsonConvert.DeserializeObject<ImageCropDataSet>(mediaItem.umbracoFile.ToString());
}
I had a quick look and it seems you mainly need to change the many Parameter.property to Model.MacroParameters["property"].ToString() and add the inherits @inherits Umbraco.Web.Macros.PartialViewMacroPage
var mediaItem = Library.MediaById(node.imageID);
var imageCrops = JsonConvert.DeserializeObject<ImageCropDataSet>(mediaItem.umbracoFile.ToString());
<img src="@imageCrops.Src"/>
Gets me the image just fine
Buuuuuuuut how do i get a cropped image? Neither of the following dows the trick:
var umbHelper = new UmbracoHelper(UmbracoContext.Current);
var typedMedia = umbHelper.TypedMedia((int)node.imageID);
<img src="@typedMedia.GetResponsiveImageUrl(100, 100)" />
var umbHelper = new UmbracoHelper(UmbracoContext.Current);
var typedMedia = umbHelper.TypedMedia(node.imageID);
<img src="@typedMedia.GetResponsiveImageUrl(100, 100)" />
Getting image in Razor Macro
Im modifying The Full tText Search Macro to suit my needs. The package uses a Razor macro.
Im trying to render an image from a document type attribute.
where @fullTextId returns the ID of the node, and @personImage returns "umbraco.MacroEngines.DynamicMedia".
So far so good!
should then return the image, but instead it returns a blob of Json
How do i get the image?
Hi Claus,
Do you have a link for that Macro code?
Thanks,
Jeavon
Hi Jeavon
I dont have a link to the macro script directly, but its this package:
http://our.umbraco.org/projects/website-utilities/full-text-search
I've tried this approach as well:
Which returns:
Ah ok, think it's this one then?
I would probably rewrite it as a Partial View Macro alternatively there is a solution here for use in a Macro Script.
Jeavon
Yeah, if i knew how ;).
Using your eample from the link above
throws an error
@sidebarImage return 2601, so it must be something with JsonConvert
Try like this:
We're getting closer :). But now its getting weird :)
Returns
Codegarden Beer Unlocked ;)
And ill try my luck at converting the macro :)
Lol :) Glad you've got it working
I had a quick look and it seems you mainly need to change the many
Parameter.property
toModel.MacroParameters["property"].ToString()
and add the inherits@inherits Umbraco.Web.Macros.PartialViewMacroPage
See... I knew it was too good to be true :)
So:
Gets me the image just fine
Buuuuuuuut how do i get a cropped image? Neither of the following dows the trick:
Ah, now you really are in the realm of needing to convert it to a Partial View Macro. I can think of a potential workaround but really.....????
I tried to convert, but it didnt work.
Have pinged the creator for a partial view macro.
Ok, how about this unnatural thing:
That's good!
Then can't you do:
Nope, that throws an error...
It works up to the <img> tag
Ah, you will need a using
@using Slimsy;
Otherwise, could you post the exception?
See, thats the fun part about these macro scripts, they dont post the exception, just:
Error loading MacroEngine script (file: FullTextSearch.cshtml)
which is pretty useless. And being a frontend, no VS im once again a bit lost :).
I have these using's:
@using Newtonsoft.Json
@using Umbraco.Web
@using Umbraco.Web.Models
@using System.Xml.XPath
@using Slimsy
@using Governor.Umbraco.FullTextSearch.Extensions
@inherits umbraco.MacroEngines.DynamicNodeContext
but still getting an error...
is working on a reply...