Using the media picker and uploader to add images.. Options
Ewatkins
Posted: Thursday, November 13, 2008 10:05:40 PM
Rank: Aficionado

Joined: 10/8/2008
Posts: 106
Location: Virginia
This applies to v4 beta 2..

I have a document type that has the upload data type and the media picker data type included in it. I can upload the image, and when I click it to view it larger I get the url, and it is placed in the media folder (then inside a random number folder ie 76) so it is www.xxx.com/media/76/image.jpg..now I want to use the media picker to pick the image out of the folder but when I open up the media picker and click on the media folder, the box just closes. It wont let me browse the media folder. Any idea as to what is going on?

Also in my template I am calling this:
<img src="<umbraco:Item field='placeImage' runat='server'></umbraco:Item>" alt="" />

placeImage is the name of the media picker. Is that correct?

Thanks
Evan
nwahlberg
Posted: Friday, November 14, 2008 4:40:25 AM

Rank: Devotee

Joined: 10/20/2008
Posts: 83
Location: USA
Ewatkins wrote:
This applies to v4 beta 2..
Also in my template I am calling this:
<img src="<umbraco:Item field='placeImage' runat='server'></umbraco:Item>" alt="" />

placeImage is the name of the media picker. Is that correct?


Hi Evan,

I ran into something similar I think (if I am understanding you correctly). What you are getting back as part of your "placeImage" field is the ID of the media item, correct? So, your image tag probably looks something like:

Code:
<img src="1025" alt="" />


To solve this, you will need to create some XSLT. I ended up using something that Douglas Robar suggested a while back that looks like this:

Code:
<!-- MACRO PARAMS -->
<xsl:variable name="imgAlias" select="/macro/imgAlias"/>

<xsl:template match="/">

<!-- start writing XSLT -->
<xsl:if test="$imgAlias != ''">
<img>
    <xsl:attribute name="src">
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias=$imgAlias], 'false')/data [@alias='umbracoFile']" />
    </xsl:attribute>
    <!--<xsl:attribute name="width">
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias=$imgAlias], 'false')/data [@alias='umbracoWidth']" />
    </xsl:attribute>
    <xsl:attribute name="height">
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias=$imgAlias], 'false')/data [@alias='umbracoHeight']" />
    </xsl:attribute>-->
    <xsl:attribute name="alt">
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias=$imgAlias], 'false')/@nodeName" />
    </xsl:attribute>
</img>
</xsl:if>
</xsl:template>


That should do the trick for ya. Just include this in a macro, and pass in the name of the field like so:

Code:
<umbraco:Macro imgAlias="nameOfImageAlias" Alias="NameOfMacro" runat="server"></umbraco:Macro>


Hope this helps.

Best,
Nik

Level 1 Certified / www.scandiaconsulting.com
norphf
Posted: Sunday, November 16, 2008 9:02:39 PM
Rank: Newbie

Joined: 7/21/2007
Posts: 14
Hi

I am trying your solution, but I don't get any output, from the macro.

My macro:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">


<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>
<xsl:variable name="imgAlias"/>
<xsl:template match="/">

<xsl:if test="$imgAlias != ''">
<img>
    <xsl:attribute name="src">
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias=$imgAlias], 'false')/data [@alias='umbracoFile']" />
    </xsl:attribute>
    <xsl:attribute name="width">
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias=$imgAlias], 'false')/data [@alias='umbracoWidth']" />
    </xsl:attribute>
    <xsl:attribute name="height">
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias=$imgAlias], 'false')/data [@alias='umbracoHeight']" />
    </xsl:attribute>
    <xsl:attribute name="alt">
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias=$imgAlias], 'false')/@nodeName" />
    </xsl:attribute>
</img>
</xsl:if>

</xsl:template>

</xsl:stylesheet>


What I use for getting it out:
Code:
<umbraco:Macro Alias="MediaIDToImage" imgAlias="1061" runat="server"></umbraco:Macro>


I am running V4 beta2.

Hope you can help me.

/Lars Mortensen
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.