MediaCurrent in macro Options
lloydphillips
Posted: Thursday, September 18, 2008 1:47:37 AM
Rank: Devotee

Joined: 5/22/2008
Posts: 69
Location: Auckland, New Zealand
I've got an issue with trying to display an image in a macro. It's driving me nuts. I've found a couple of posts with similar issues but either no one seems to find an answer or the person must have found their answer and not posted their solution as the posts just kind of stop. :(

Anyway, I've got 2 variables declared in my XSLT doc:
<xsl:variable name="freeTrialPage" select="/macro/freeTrial" />
<xsl:variable name="freeTrialImage" select="/macro/freeTrialImage" />

freeTrialPage is a contentPicker and works fine. freeTrialImage is my mediaCurrent. This is my code:

Code:

<xsl:if test="($freeTrialPage!= '') and ($freeTrialImage!='')">
<a href='{umbraco.library:NiceUrl($freeTrialPage)}' title='Sign up now for a FREE trial!'>

<xsl:value-of select="umbraco.library:GetMedia($freeTrialImage/data [@alias = 'image'], 'false')/data [@alias = 'umbracoFile']"/>
</a>
</xsl:if>


This saves ok but I get this error: Error parsing XSLT file: \xslt\FeatureList.xslt

Debug info is spitting this out:

Debug from Feature List
<macro><freeTrialImage><node id="1365" version="f1153940-7abd-4812-a16f-c02715ea8892" parentID="-1" level="1" writerID="6" nodeType="1032" template="0" sortOrder="2" createDate="2008-09-09T15:27:54" updateDate="2008-09-09T15:27:54" nodeName="Try CubeIQ Button" urlName="trycubeiqbutton" writerName="Lloyd" nodeTypeAlias="Image" path="-1,1365"><data alias="umbracoFile">/media/8806/layout-home-signup_07.gif</data><data alias="umbracoWidth">360</data><data alias="umbracoHeight">50</data><data alias="umbracoBytes">4150</data><data alias="umbracoExtension">gif</data></node></freeTrialImage><freeTrial>1352</freeTrial></macro>

I'm not sure where I am going wrong. I'm presently suspecting that it has something to do with me using [@alias='image'] but I can't be sure why. I thought I'd post because I've been banging my head on the screen for nearly an hour and all I want to do is display a simple image.
Brick wall

Any ideas?

lloyd
bootnumlock
Posted: Thursday, September 18, 2008 4:48:41 AM

Rank: Fanatic

Joined: 10/9/2006
Posts: 460
Location: batavia, IL
is the image assigned in the macro or on teh docType? you also might want to change that alias name from image to see if that does anything... i think everything you have looks good otherwise.

bootnumlock - aka bob baty-barr
My Packages Site: http://packages.maliciousthinktank.com
Business Blog: http://www.maliciousthinktank.com/blog
Personal site: http://www.baty-barr.com
Level 1 Certified!
lloydphillips
Posted: Thursday, September 18, 2008 5:15:24 AM
Rank: Devotee

Joined: 5/22/2008
Posts: 69
Location: Auckland, New Zealand
I tried specifying the image in the macro but now I have it via a mediaPicker so my macro placed on the page looks like this:

<?UMBRACO_MACRO macroAlias="FeatureList" currentPage="" freeTrial="1352" freeTrialImage="1365"></?UMBRACO_MACRO>

I've tried removing the image alias too (I thought it was looking under the wrong node) and renaming it also but neither have helped.
VirtualRichard
Posted: Thursday, September 18, 2008 12:53:41 PM

Rank: Fanatic

Joined: 9/17/2007
Posts: 265
Location: London, UK.
I'm paraphrasing horribly here but for:

Code:
<?UMBRACO_MACRO macroAlias="Image" ImageNode="2003"></?UMBRACO_MACRO>

Something like:

Code:
<xsl:variable name="ImageNode" select="/macro/ImageNode/node/@id" />

<xsl:variable name="parent" select="umbraco.library:GetMedia($ImageNode, 'false')" />

<xsl:for-each select="$parent/node">

<xsl:if test="./data [@alias = 'umbracoExtension'] = 'gif' or ./data [@alias = 'umbracoExtension'] = 'jpg' or ./data [@alias = 'umbracoExtension'] = 'jpeg' or ./data [@alias = 'umbracoExtension'] = 'png'">

    <xsl:element name="img">
        <xsl:attribute name="src"><xsl:value-of select="./data [@alias = 'umbracoFile']"/></xsl:attribute>
    </xsl:element>

</xsl:if>

</xsl:for-each>

It's an extract from something that works perfectly for the specific task I needed but it might be helpful to you?

Richard

2 * 3 * 3 * 37 : The prime factorisation of The Beast.
lloydphillips
Posted: Monday, September 22, 2008 1:08:33 AM
Rank: Devotee

Joined: 5/22/2008
Posts: 69
Location: Auckland, New Zealand
Thanks Richard,

It's not quite helped as I'm using the MediaPicker. If I use the node id hard coded like so it works fine:

Code:

<xsl:if test="$freeTrialImage!= ''">
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia(1365, 'false')/data [@alias = 'umbracoFile']"/>
</xsl:attribute>
</xsl:element>
</xsl:if>


However, with the media picker my variable isn't returning a nodeId (as I would expect) and I'm getting a chunk of data back which includes the url I need.

The exact same issue was reported by Heather on this thread http://forum.umbraco.org/yaf_postst4525_New-Macro-Parameter-Type-mediaPicker.aspx but it doesn't appear to have been solved. I'm not sure how to get at the umbracoFile data that is in the output or remove the other details that are appended to the string that is being output when I print out my variable returned by the media picker. So, if I use this code.

Code:

<xsl:variable name="freeTrialImage" select="/macro/freeTrialImage" />

<xsl:value-of select="$freeTrialImage"/>


Where freeTrialImage is data returned from my mediaPicker then this is the output printed to the screen:

/media/8806/layout-home-signup_07.gif360504150gif

Is this a concatenation of all the node data? What is returned from the media picker is it a node or a node id? If it's a node how do I extract the data.

Also, might be important to note, I'm NOT doing this in any for each loop. It's one alias set up on a macro to place an image at the top of section.
drobar
Posted: Monday, September 22, 2008 2:53:16 AM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,831
Location: MA, USA
You're right that you're getting the entire media node data. With a value-of it is just concatinated together. If you use
Code:
<xsl:copy-of select="$freeTrialImage"/>

And then look at the html code in your browser when you run the macro you'll see the entire node data, which will show you the part you want to get in your select= statement.

In short, just change your code to...

Code:
<xsl:variable name="freeTrialImage" select="/macro/freeTrialImage" />

<xsl:value-of select="$freeTrialImage/data[@alias='umbracoFile']"/>


This should give you /media/8806/layout-home-signup_07.gif

If you want to put that in an img tag, just do the following...

Code:
<xsl:variable name="freeTrialImage" select="/macro/freeTrialImage" />

<img>
    <xsl:attribute name="src">
        <xsl:value-of select="$freeTrialImage/data[@alias='umbracoFile']"/>
    </xsl:attribute>
</img>


cheers,
doug.

MVP 2007-2009 - Percipient Studios
lloydphillips
Posted: Sunday, September 28, 2008 11:36:40 PM
Rank: Devotee

Joined: 5/22/2008
Posts: 69
Location: Auckland, New Zealand
Hey Doug

That doesn't seem to be working. I'm just getting a blank section where the image should be displayed.

Lloyd
lloydphillips
Posted: Monday, September 29, 2008 12:03:06 AM
Rank: Devotee

Joined: 5/22/2008
Posts: 69
Location: Auckland, New Zealand
BTW my copy-of data is producing:

<cubeIQfreeTrialImage><node id="1365" version="f1153940-7abd-4812-a16f-c02715ea8892" parentID="-1" level="1" writerID="6" nodeType="1032" template="0" sortOrder="2" createDate="2008-09-09T15:27:54" updateDate="2008-09-09T15:27:54" nodeName="Try CubeIQ Button" urlName="trycubeiqbutton" writerName="Lloyd" nodeTypeAlias="Image" path="-1,1365"><data alias="umbracoFile">/media/8806/layout-home-signup_07.gif</data><data alias="umbracoWidth">360</data><data alias="umbracoHeight">50</data><data alias="umbracoBytes">4150</data><data alias="umbracoExtension">gif</data></node></cubeIQfreeTrialImage>

but referencing data and then the umbracoFile alias just isn't returning anything.

:(
drobar
Posted: Monday, September 29, 2008 3:06:19 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,831
Location: MA, USA
Thanks for the copy-of output, very helpful! It looks like you'll need to reference the 'node' in the path as well. You can either modify the variable or the value-of... both give the same result but if you call it more than once setting the variable will save a couple characters in your code (this is probably needless "optimization", so do whichever you prefer).

Code:
<xsl:variable name="freeTrialImage" select="/macro/freeTrialImage/node" />


Does that do it?

cheers,
doug.

MVP 2007-2009 - Percipient Studios
Ig_p118
Posted: Sunday, November 02, 2008 7:50:01 PM

Rank: Fanatic

Joined: 7/21/2006
Posts: 315
Location: Salerno - Italy
drobar wrote:
Thanks for the copy-of output, very helpful! It looks like you'll need to reference the 'node' in the path as well. You can either modify the variable or the value-of... both give the same result but if you call it more than once setting the variable will save a couple characters in your code (this is probably needless "optimization", so do whichever you prefer).

Code:
<xsl:variable name="freeTrialImage" select="/macro/freeTrialImage/node" />


Does that do it?

cheers,
doug.


works with <xsl:variable name="ImageID" select="/macro/imgAlias/node/@id" /> not with node only.



Red Consulting s.a.s - Umbraco from v1.0
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.