I've created simple media pickers before using the umbraco library, but can't get it to fly in 4.6.1.
When using select of, it wont accept the old syntax $currentPage/data [@alias = "mediaItem"], but suggests <xsl:value-of select="$currentPage/pageImage"/>. This produces an ID in visualizer, no problem.
It arises when creating:<xsl:value-of select="umbraco.library:GetMedia($currentPage/pageImage, 'false')"/>. Neither the older syntax or this I have tried works without an error on saving: System.OverflowException: Value was either too large or too small for an Int32.
If you are getting this error on saving it may be because there is no $currentPage when you save, which always throws an exception calling the library functions.
If it is this, you can either uncheck the validation on save and it will work when it is embedded on content; or because I like everything to work everywhere, what I normally do is create an xsl:variable for the media ID and use an xsl:choose element to set it to 1 when there is no current page.
Thanks for the speedy replies! For starters, I have everything in place: page, property (pageImage) macro, xslt. Oddly, enough, I can save it with another property name, but get an error with pageItem, and I am certain spelling/casing is correct.
I have tried that, but get an error (System.OverflowException: Værdien var enten for stor eller for lille til en Int32) unless I check "Skip testing (ignore errors)". It does work if I turn errors off, but I'm still puzzled.
Bo, I got it to work fine on another xslt page, running on a different macro/template. I'm suspecting something is amiss with the structure of my template or...? Hmmm.
The above might not work; you can't pass empty strings into the library functions, so you need to check the media ID before you pass it in. You could then check the media item afterwards in case the ID has since been deleted for completeness. This will also deal with no current page on save because the mediaID will be blank in that case too:
@Rob: That was the test I was looking for. Have not tried it yet, but I will check it out asap. This should also prevent the browser from returning an error if certain pages do not inject an image in the propert/media picker, I would assume?
It should do, give it a whirl - it was straight from brain to forum, so it may not work, but I've just had a look at what I'm using in an ImageGen portfolio doobrie I wrote and it looks basically the same.
Repeat for title and any other attributes that may or may not be present.
That will result in neater markup if the attributes are not present.
One caveat with that is that I'm pretty sure that alt is a required attribute on the XHTML doctypes at least, so if W3C validation is important to you you may in fact want to force that to the filename or something if it is not present (if umbraco does not already do that).
Yeah, sorry, I guess my question was not clear. I mean, how can alt tags be written at all with the media picker, or in the tinyMCE editor, for that matter? There are no fields. I would like to include these. Any ideas how to add them? This is another topic altogether. Just thought you might know.
Aha, no, sorry, not something I've ever done I'm afraid! I do vaguely recall looking at the media picker and wondering why it didn't allow you to allow alt tags though; I never followed it up though.
Problem: Media Picker xslt in 4.6.1
Hi,
I've created simple media pickers before using the umbraco library, but can't get it to fly in 4.6.1.
When using select of, it wont accept the old syntax $currentPage/data [@alias = "mediaItem"], but suggests <xsl:value-of select="$currentPage/pageImage"/>. This produces an ID in visualizer, no problem.
It arises when creating: <xsl:value-of select="umbraco.library:GetMedia($currentPage/pageImage, 'false')"/>. Neither the older syntax or this I have tried works without an error on saving: System.OverflowException: Value was either too large or too small for an Int32.
Can anyone help out?
Hi Dwayne,
Sound weird - are you using the GetMedia() inside a loop? :-)
I just checked my xslt for my latest where I'm doing the exact same using the new scheme, my code looks like this:
<xsl:for-each select="$currentPage/ancestor-or-self::*/*/Reklame [@isDoc]">
<xsl:variable name="media" select="umbraco.library:GetMedia(current()/billede, 0)" />
Can I maybe trick you into pasting some more of your code?
Thanks!
/ Bo
Just noticed that you're using:
<xsl:value-of select="umbraco.library:GetMedia($currentPage/pageImage, 'false')"/>
Try it like this:
</img>
See if that works :-)
If you are getting this error on saving it may be because there is no $currentPage when you save, which always throws an exception calling the library functions.
If it is this, you can either uncheck the validation on save and it will work when it is embedded on content; or because I like everything to work everywhere, what I normally do is create an xsl:variable for the media ID and use an xsl:choose element to set it to 1 when there is no current page.
Thanks for the speedy replies! For starters, I have everything in place: page, property (pageImage) macro, xslt. Oddly, enough, I can save it with another property name, but get an error with pageItem, and I am certain spelling/casing is correct.
@Bo: Sure thing. See what you can make of it.
@Rob: I have a page. The macro is in place in a template.
Dwayne,
Try this and see if it works for you :-)
</img>
/ Bo
Hej Bo,
I have tried that, but get an error (System.OverflowException: Værdien var enten for stor eller for lille til en Int32) unless I check "Skip testing (ignore errors)". It does work if I turn errors off, but I'm still puzzled.
Bo, I got it to work fine on another xslt page, running on a different macro/template. I'm suspecting something is amiss with the structure of my template or...? Hmmm.
Also, I got this to work as well.
Now I have a new issue when a child page on the template does not require an image, The browser returns a parsing error. Any tips on creating a test?
Hi again Dwayne,
It sure sounds weird that it works on another template, what exactly would be the difference from one template to another? :-)
I think you could make a test to see if the mediapicker holds an media item, something like this:
.. or:
I can't remember exactly which of these it is ;-)
Let me know if it works for you!
Thanks,
Bo
The above might not work; you can't pass empty strings into the library functions, so you need to check the media ID before you pass it in. You could then check the media item afterwards in case the ID has since been deleted for completeness. This will also deal with no current page on save because the mediaID will be blank in that case too:
@Rob: That was the test I was looking for. Have not tried it yet, but I will check it out asap. This should also prevent the browser from returning an error if certain pages do not inject an image in the propert/media picker, I would assume?
It should do, give it a whirl - it was straight from brain to forum, so it may not work, but I've just had a look at what I'm using in an ImageGen portfolio doobrie I wrote and it looks basically the same.
Thanks Rob. That did the trick it seems. Sorry it took a while to get back. Swamped ;-)
What's the best way to set parameters on media picker? Here I'm thinking particulary of alt tags a user can set when chosing an image..
I'm not sure I understand your question - do you mean dealing with both cases when there are alt tags, and when there aren't?
If so, I would do this:
Repeat for title and any other attributes that may or may not be present.
That will result in neater markup if the attributes are not present.
One caveat with that is that I'm pretty sure that alt is a required attribute on the XHTML doctypes at least, so if W3C validation is important to you you may in fact want to force that to the filename or something if it is not present (if umbraco does not already do that).
Yeah, sorry, I guess my question was not clear. I mean, how can alt tags be written at all with the media picker, or in the tinyMCE editor, for that matter? There are no fields. I would like to include these. Any ideas how to add them? This is another topic altogether. Just thought you might know.
Aha, no, sorry, not something I've ever done I'm afraid! I do vaguely recall looking at the media picker and wondering why it didn't allow you to allow alt tags though; I never followed it up though.
Yeah, I find it bizarre it's not a defacto parameter, among others. I'll have to dig elsewhere. Thanks again Rob for the help with the xsl.
is working on a reply...