Media picker property + images Options
mrshrinkray
Posted: Monday, August 07, 2006 4:47:05 PM

Rank: Aficionado

Joined: 8/4/2006
Posts: 106
Location: London
Is there anyway to utilise the Media picker property type in a template, so I can use its value for an image? It currently outputs a number, and I haven't found a way to turn this into its actual URL.

Thanks
Hay
Posted: Monday, August 07, 2006 5:10:32 PM
Rank: Devotee

Joined: 8/2/2006
Posts: 47
Use this to convert it to a path.

<img src="{umbraco.library:NiceUrl(@id)}" />
Hay
Posted: Monday, August 07, 2006 5:11:18 PM
Rank: Devotee

Joined: 8/2/2006
Posts: 47
{umbraco.library:NiceUrl(@id)}

Arg!!! We need to be able to post code here!
mrshrinkray
Posted: Monday, August 07, 2006 5:19:29 PM

Rank: Aficionado

Joined: 8/4/2006
Posts: 106
Location: London
Does this go inside the <?UMBRACO_GETITEM tag?
mrshrinkray
Posted: Monday, August 07, 2006 5:20:02 PM

Rank: Aficionado

Joined: 8/4/2006
Posts: 106
Location: London
&lt;?UMBRACO_GETITEM tag

^^
mrshrinkray
Posted: Monday, August 07, 2006 5:21:17 PM

Rank: Aficionado

Joined: 8/4/2006
Posts: 106
Location: London
Start again. Does this go inside the &lt;?UMBRACO_GETITEM tag

Surely the body of this text is htmlencoded, so &lt; are replaced with & lt;
pph
Posted: Monday, August 07, 2006 5:29:32 PM
Rank: Aficionado

Joined: 7/19/2006
Posts: 165
Location: aalleren, Denmark
You can't use the media pickers' value directly in a template atm. You would have to use a xslt macro to parse the ID to an image url with getmedia().

Another option could be to use the upload field editor control instead of the mediapicker as it outputs the actually path of the uploaded image, but depends on what you planned to do with it ofcourse.

Umbracian Personal blog: Objects.dk
mrshrinkray
Posted: Monday, August 07, 2006 5:30:37 PM

Rank: Aficionado

Joined: 8/4/2006
Posts: 106
Location: London
It's for a header image for each page. I want to re-use ones in the media library rather than having to upload each time.
warren
Posted: Monday, August 07, 2006 6:09:30 PM

Rank: Addict

Joined: 7/19/2006
Posts: 777
Location: Leigh-on-Sea, Essex, UK
Create a macro with a similar XSLT as mine below.

<a href="http://jfs.momo.co.uk/xslt/getimage.xslt">http://jfs.momo.co.uk/xslt/getimage.xslt</a>

Then put the macro in the relevent place in the template.

Hope this helps.
Warren

Warren Buckley an Umbraco MVP 08-09 & level 1 certified developer
jesper
Posted: Monday, August 07, 2006 10:40:27 PM

Rank: Administration

Joined: 7/25/2006
Posts: 415
Location: vipperoed, denmark
If it's design elements used in templates they seldom need updating capabilities. I usually put them outside Umbraco. This requires some ftp access of cause.

best,

Jesper

webbureau jesper.com doing webdesign / development / umbraco implementations / 2007&2008 MVP
mrshrinkray
Posted: Tuesday, August 08, 2006 3:51:44 PM

Rank: Aficionado

Joined: 8/4/2006
Posts: 106
Location: London
I get:

System.Xml.Xsl.XsltException: Function 'umbraco.library:GetMedia()' has failed. ---> System.ArgumentException: Cannot widen from target type to primitive type.

With that XSL template. Am I missing something obvious?
clementM
Posted: Tuesday, August 08, 2006 7:00:36 PM
Rank: Devotee

Joined: 7/25/2006
Posts: 35
Just write an xsl:if tag around the call of the GetMedia function like :

xsl:if test="$mediaID != ''"
... GetMedia ...
/xsl:if
Maedhros
Posted: Friday, August 11, 2006 1:58:46 PM
Rank: Enthusiast

Joined: 7/26/2006
Posts: 29
I'm sitting with a similar problem.

I created the macro and xslt file. From the xslt I only want the url and nothing else. In my case I'm using the url for the background in the template via CSS.

My xslt body contains only the part:
{umbraco.library:GetMedia($currentPage/data [@alias = 'BackgroundImage'],
'false')/data [@alias = 'umbracoFile']}

The macro outputs the whole line instead of just executing the function and returning the url. I tried to change the xsl:output method to "text", but it does not help. I have to wrap some xml/html around the line to make it process it correctly.

Is there a way to avoid this? I only need the url and that's it.
Maedhros
Posted: Friday, August 11, 2006 2:00:53 PM
Rank: Enthusiast

Joined: 7/26/2006
Posts: 29
BTW.... I added the BackGround property (as a media picker) to the document type in "Generic Properties".
Maedhros
Posted: Friday, August 11, 2006 3:16:10 PM
Rank: Enthusiast

Joined: 7/26/2006
Posts: 29
I found out about getting the output just as the url.

But testing whether or not there is a background media id is bugging a bit.

xsl:if test="$mediaID != ''"

what is $mediaID ?
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.