I want to do something fairly straightforward but can find no help for it. I need to use the standard Media picker in umbraco 4 to pick content, and through using a macro, present it as an image.I need to use the media picker as the image will be sized correctly, and will be reused on many pages
I've got the media in the library but now need some help creating a macro to show that media as an image. The page I want to show the image on is working fine, and there is a property on it (bannerImage) which represents the image
<umbraco:Item runat="server" field="bannerImage"/> does not work (didn't expect it to, but wild shot in the dark) - this just shows the id of the media
Has anyone done anything like this, or able to point me in the right direction so I can get started
The macro has 2 parameters?: mediaId - which is a media node id usually coming from a media picker, and a style string - just in case I want to add some forced styling to the image.
Hopefully this will do what you want, or can be easily adapted for you
That's great - it's 99% of what I want. I'm trying to find a way of using a property in the Macro though so that I can set one of the properties (mediaID) using a media picker on the template.
Essentially what I have is below - the first line is the media picker with a static media ID, but is there any way to get the bannerImage field into that Macro
I'm trying do something like what is talk where, i tryed the examples in this thread and others but isn't working for me, i canĀ“t get the url for the image to appear.
I want to put a Logo image for my site using a parameter , type contentMedia.
I created a macro with a parameter and put it in the master page:
Also, FYI, you should replace 'true' with true(), the GetMedia function is meant to accept a bool and I think if you pass a string it always evaluates to true.
Try wrapping your GetMedia call in a test to verify $logoid has a value - otherwise you can get a parsing error when saving since it tries to test your XSLT but doesn't have a value, ex:
I saw that the other example dont have it like mine xslt but that gives me the id of the media file, logoid will get 1149 , because i need it for the GetMedia().
okay.. it has been ages since the last post. but i think i just had the same problem like Pedro.
I have a couple of images that were auto-uploaded by LiveWriter which has '~' in umbracoFile element whereas normal uploaded images doesn't. The system is throwing error on this.
I got this resolved by removing the '~' in the xslt.
Macro to show an image from Media
Hi Guys n Gals
I want to do something fairly straightforward but can find no help for it. I need to use the standard Media picker in umbraco 4 to pick content, and through using a macro, present it as an image.I need to use the media picker as the image will be sized correctly, and will be reused on many pages
I've got the media in the library but now need some help creating a macro to show that media as an image. The page I want to show the image on is working fine, and there is a property on it (bannerImage) which represents the image
<umbraco:Item runat="server" field="bannerImage"/> does not work (didn't expect it to, but wild shot in the dark) - this just shows the id of the media
Has anyone done anything like this, or able to point me in the right direction so I can get started
thanks
Carl
Hi Carl
Here's a pointer to get you started:
http://wifi.umbraco.org/forum/developers/xslt/5238-List-all-images-in-a-media-folder-using-XSLT
/Finn
Carl,
you can use inline xslt in your template to show the image:
Hope this helps.
Regards,
/Dirk
Hi Carl,
I have a Macro for doing exactly that:
The macro has 2 parameters?: mediaId - which is a media node id usually coming from a media picker, and a style string - just in case I want to add some forced styling to the image.
Hopefully this will do what you want, or can be easily adapted for you
/Josh
Hi Josh
That's great - it's 99% of what I want. I'm trying to find a way of using a property in the Macro though so that I can set one of the properties (mediaID) using a media picker on the template.
Essentially what I have is below - the first line is the media picker with a static media ID, but is there any way to get the bannerImage field into that Macro
<!-- Banner Image Macro -->
<umbraco:Macro mediaId="1079" style="" Alias="MediaImage" runat="server"></umbraco:Macro>
<umbraco:Item runat="server" field="bannerImage"/>
Thanks for your help - I'm pretty new at all this, but enjoying the exp so far
Carl
Hi All
I found an anwer - it is indeed possible.
http://umbraco.org/documentation/books/macro-parameters-syntax/advanced-parameter-syntax
Essentially you use "the Bracket syntax" - live the name. So the macro would become
<!-- Banner Image Macro -->
<umbraco:Macro mediaId="[$bannerImage]" style="" Alias="MediaImage" runat="server"></umbraco:Macro>
Where bannerImage was a page property for a media picker
thnks for quick reply. now im doing that..
Hi all, i'm new with umbraco.
I'm trying do something like what is talk where, i tryed the examples in this thread and others but isn't working for me, i canĀ“t get the url for the image to appear.
I want to put a Logo image for my site using a parameter , type contentMedia.
I created a macro with a parameter and put it in the master page:
My XSLT file:
...
...
My XML for the variable image is:
this "$image/@nodeName" gives me "logo" my problem is getting umbracoFile, return empty.
<img scr="" alt="logo" />
What have i'm doing wrong?
Hi,
You're close, the issue is that you are using some of the old schema syntax (data [@alias....]) to retrieve the umbracoFile property, instead use:
Also, FYI, you should replace 'true' with true(), the GetMedia function is meant to accept a bool and I think if you pass a string it always evaluates to true.
-Tom
Thanks Tom for your reply,
I already test it like you said and like http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia
But like that i get: Error parsing XSLT file: \xslt\BindLogo.xslt
I put
Try wrapping your GetMedia call in a test to verify $logoid has a value - otherwise you can get a parsing error when saving since it tries to test your XSLT but doesn't have a value, ex:
See this blog post for more info also: http://blog.leekelleher.com/2010/08/11/how-to-use-umbraco-library-getmedia-in-xslt-for-umbraco-v4-5/
-Tom
I saw that blog post too :) and tryed the example but still getting: Error parsing XSLT file: \xslt\BindLogo.xslt.
If i remove the
{$image/umbracoFile}
from src="" and it display the tag img only with the logo alt text
if i put src="{$image/umbracoHeight}" it works and i get the height.
Its strange not working with umbracoFile.
I could be anything else besides the xslt?
I have umbraco v 4.7.1 (Assembly version: 1.0.4281.20201)
Hey Pedro,
It might be more useful to post your whole xslt.
Rich
Hi Rich, this is my xslt
Hey Pedro,
I think this line is your problem
You just needRich
Rich, why this could be the problem?
I saw that the other example dont have it like mine xslt but that gives me the id of the media file, logoid will get 1149 , because i need it for the GetMedia().
My problem is using src="{$image/umbracoFile}
I think he's using the mediaCurrent parameter for LogoID which is why he's using /Image/@id
Really since you are using mediaCurrent you don't need to use GetMedia, the media's XML is already there in the macro parameter, you can just do
or
But theoretically your code should work anyway. I don't know why you'd be getting a parsing error, I pasted the code here and it's fine...hmm.
-Tom
Hey Pedro,
So the ID of your image file node is 1149?
I can't see where your error is, but what happens if you use this code
<xsl:variable name="mediaId" select="1149" /> <xsl:if test="$mediaId > 0"> <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" /> <xsl:if test="$mediaNode/umbracoFile"> <img src="{$mediaNode/umbracoFile}" height="{umbracoHeight}" width="{umbracoWidth}" /> </xsl:if> </xsl:if>Posted at the same time as Tom, hopefully one of the posts should help you.
Rich
okay.. it has been ages since the last post. but i think i just had the same problem like Pedro.
I have a couple of images that were auto-uploaded by LiveWriter which has '~' in umbracoFile element whereas normal uploaded images doesn't. The system is throwing error on this.
I got this resolved by removing the '~' in the xslt.
Mine is running on umbraco.4.7.1, blog4umbraco.
is working on a reply...