I have an asset's Label (the title text you type above its description) and need to get the asset's ID. Can anyone suggest a technique for doing so?
The scenario is this: I've gotten the Entry Body, and it contains an image embedded in the text by the author. The image's alt tag contains the image's label. I can get the label into a variable. Now I want to use that to call up the ID of the asset with that label. I'm willing to assume that this post only has one asset with this particular Label.
thanks!
Reported on Movable Type 4.2

The better question is how you are adding the asset to the page. Are you using mt asset tags or creating the link yourself?
The author's adding the image in the body of the post; MovableType is adding the HTML and associating the asset with the post. So, as it currently stands, the template developer (me) doesn't get a chance to add the image by using asset tags *or* by writing out the HTML for the image.
When MovableType adds the image to the post's body, it inserts code that looks like this:
<span class="mt-enclosure mt-enclosure-image" style="display:
inline;"><img alt="Thumbnail image for 349px-Glass_of_Jamesons.jpg"
src="http://obscured.org/test2010/assets_c/2010/01/349px-Glass_of_Jamesons-
thumb-200x343.jpg" class="mt-image-left" style="margin: 0pt 20px 20px 0pt;
float: left;" width="200" height="343" /></span>
That's why I need to use the asset label to get the ID. The only identifying info in there is the label and the filepath (and perhaps the image size).
Once I have that, I intend to do a regex_replace to replace the old code for the image with better code. -- and *then* I'll finally be using asset tags to write the images.
I think the Better File Upload plugin will set you up. Otherwise you have two options:
- modify the template that MT uses to generate that piece of code, and place an AssetID tag where you need it
- write a plugin that does the same on the fly
Thanks, Francois. The first two options failed me (well, Better File Upload didn't fail me, but I'm not using it, so...) and the third is what I'm hacking at.
This is currently working for me (hack warning!):