user-pic

Asset ID from Label

Vote 0 Votes

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

5 Replies

| Add a Reply
  • 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!):

    <mt:ignore>
    	For all of this post's assets, find which ones the
    	author inserted into the story.
    </mt:ignore>
    <mt:Assets>
    	<mt:AssetLabel setvar="my_asset_label" />
    	<mt:ignore>
    		Is the asset label text within the body content?
    		The 'like' pattern must *not* be within regex
    		pattern delimiters:
    	</mt:ignore>
    	<mt:if name="body_content"
    	like="$my_asset_label">
    		<mt:ignore>
    			Set the rest of the variables
    			set up the replacement text
    			Replace images with MT formatting w/ my image
    			HTML
    		</mt:ignore>
    		<mt:AssetID setvar="my_asset_id" />
    		<mt:ignore>
    			MovableType's default image block (when using MT
    			4.21, anyway)
    		</mt:ignore>
    		<mt:SetVarBlock name="new_image_block">
    		A block of image code including: <mt:var
    		name="my_asset_id">
    		</mt:SetVarBlock>
    	</mt:if>
    	<blockquote style="background:
    	#ff0;"><mt:var
    	name="my_asset_label"></blockquote>
    </mt:Assets>
    
  • 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.

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1773 6162

Last Topic: Excluding categories from blog by kholechek on Feb 9, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1429 5077

Last Topic: What apocalypse hit this community in the middle of 2011? by 75th on Feb 10, 2012

694 2908

Last Topic: Blogspot to Movable Type by sdude on Feb 8, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

173 737

Last Topic: About the MT version stated in HTML source by Alex E. Schneider on Feb 7, 2012

190 565

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012