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

4 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>
    

Add a Reply

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

Forum Groups

64 196

Last Topic: movable type 5 custom fields by kljx on Mar 17, 2010

1004 3223

Last Topic: Create Offline Backup by Jackie on Mar 17, 2010

482 1976

Last Topic: ¿Any command line tool to rebuild MT? by Nicolás on Mar 16, 2010

102 360

Last Topic: Saving an entry...what is happening by jdbeast00 on Mar 12, 2010

57 127

Last Topic: Anyone using Disqus with MT5? by Jim S. on Mar 17, 2010

19 69

Last Topic: Custom main index page by Richard on Feb 7, 2010

43 172

Last Topic: by MG on Feb 20, 2010

11 22

Last Topic: Monthly Calendars Help Needed by joe leblanc on Jan 19, 2010

91 326

Last Topic: SpamLookup Keyword Filter 2.1 not work by b.n09 on Nov 17, 2009

55 205

Last Topic: URL Problems by NoSnaiL on Mar 17, 2010

code.sixapart.com

129 448

Last Topic: Action Stream for Google Buzz by jack lail on Feb 16, 2010

160 498

Last Topic: Installed custom Asset markup by spierce on Mar 15, 2010