<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://forums.movabletype.org/2010/01/asset-id-from-label.html" />
  <link rel="self" type="application/atom+xml" href="http://forums.movabletype.org/atom.xml" />
  <id>tag:forums.movabletype.org,2011://24/tag:forums.movabletype.org,2010://24.19306-</id>
  <updated>2011-09-01T02:20:25Z</updated>
  <title>Comments for Asset ID from Label</title>
  
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.292</generator>
  <entry>
    <id>tag:forums.movabletype.org,2010://24.19306</id>
    <link rel="alternate" type="text/html" href="http://forums.movabletype.org/2010/01/asset-id-from-label.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.movabletype.org/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=24/entry_id=19306" title="Asset ID from Label" />
    <published>2010-01-21T03:58:57Z</published>
    <updated>2010-09-13T12:48:08Z</updated>
    <title>Asset ID from Label</title>
    <summary>I have an asset&apos;s Label (the title text you type above its description) and need to get the asset&apos;s ID. Can anyone suggest a technique for doing so? The scenario is this: I&apos;ve gotten the Entry Body, and it contains...</summary>
    <author>
      <name>MG</name>
      
    </author>
    
    <category term="Design, Templates, &amp; Tags" />
    
    <content type="html" xml:lang="en" xml:base="http://forums.movabletype.org/">
      <![CDATA[<p>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?</p>

<p>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.</p>

<p>thanks!</p>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:forums.movabletype.org,2010://24.19306-comment:35996</id>
    <thr:in-reply-to ref="tag:forums.movabletype.org,2010://24.19306" type="text/html" href="http://forums.movabletype.org/2010/01/asset-id-from-label.html"/>
    <link rel="alternate" type="text/html" href="http://forums.movabletype.org/2010/01/asset-id-from-label.html#c35996" />
    <title>Comment from Mike T on 2010-01-21</title>
    <author>
        <name>Mike T</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>The better question is how you are adding the asset to the page. Are you using mt asset tags or creating the link yourself?</p>]]>
    </content>
    <published>2010-01-21T11:43:47Z</published>
  </entry>

  <entry>
    <id>tag:forums.movabletype.org,2010://24.19306-comment:36022</id>
    <thr:in-reply-to ref="tag:forums.movabletype.org,2010://24.19306" type="text/html" href="http://forums.movabletype.org/2010/01/asset-id-from-label.html"/>
    <link rel="alternate" type="text/html" href="http://forums.movabletype.org/2010/01/asset-id-from-label.html#c36022" />
    <title>Comment from MG on 2010-01-21</title>
    <author>
        <name>MG</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>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.</p>

<p>When MovableType adds the image to the post's body, it inserts code that looks like this:</p>

<p><br />
&lt;span class="mt-enclosure mt-enclosure-image" style="display:<br />
inline;"&gt;&lt;img alt="Thumbnail image for 349px-Glass_of_Jamesons.jpg"<br />
src="http://obscured.org/test2010/assets_c/2010/01/349px-Glass_of_Jamesons-<br />
thumb-200x343.jpg" class="mt-image-left" style="margin: 0pt 20px 20px 0pt;<br />
float: left;" width="200" height="343" /&gt;&lt;/span&gt;<br />
</p>

<p><br />
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).</p>

<p>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.<br />
</p>]]>
    </content>
    <published>2010-01-21T16:36:23Z</published>
  </entry>

  <entry>
    <id>tag:forums.movabletype.org,2010://24.19306-comment:36232</id>
    <thr:in-reply-to ref="tag:forums.movabletype.org,2010://24.19306" type="text/html" href="http://forums.movabletype.org/2010/01/asset-id-from-label.html"/>
    <link rel="alternate" type="text/html" href="http://forums.movabletype.org/2010/01/asset-id-from-label.html#c36232" />
    <title>Comment from François Nonnenmacher on 2010-01-26</title>
    <author>
        <name>François Nonnenmacher</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>I think the Better File Upload plugin will set you up. Otherwise you have two options:<br />
- modify the template that MT uses to generate that piece of code, and place an AssetID tag where you need it<br />
- write a plugin that does the same on the fly<br />
</p>]]>
    </content>
    <published>2010-01-26T08:46:23Z</published>
  </entry>

  <entry>
    <id>tag:forums.movabletype.org,2010://24.19306-comment:36242</id>
    <thr:in-reply-to ref="tag:forums.movabletype.org,2010://24.19306" type="text/html" href="http://forums.movabletype.org/2010/01/asset-id-from-label.html"/>
    <link rel="alternate" type="text/html" href="http://forums.movabletype.org/2010/01/asset-id-from-label.html#c36242" />
    <title>Comment from MG on 2010-01-26</title>
    <author>
        <name>MG</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>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.</p>

<p>This is currently working for me (hack warning!):</p>

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

  <entry>
    <id>tag:forums.movabletype.org,2010://24.19306-comment:46755</id>
    <thr:in-reply-to ref="tag:forums.movabletype.org,2010://24.19306" type="text/html" href="http://forums.movabletype.org/2010/01/asset-id-from-label.html"/>
    <link rel="alternate" type="text/html" href="http://forums.movabletype.org/2010/01/asset-id-from-label.html#c46755" />
    <title>Comment from hurriyet on 2010-09-13</title>
    <author>
        <name>hurriyet</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>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.</p>]]>
    </content>
    <published>2010-09-13T12:48:08Z</published>
  </entry>

</feed>

