Help - Search - Members - Calendar
Full Version: Custom Fields - Images And Assets
Movable Type Community Forum > Using Movable Type > Templates and Tags
ghost robot
Using Custom Fields to embed images to your entry.

After working for hours to figure this out here's what i have found with adding images to your entry using custom fields.

I created a Custom Field for System Object = "Entry" called 'assettest' this gives you the sample code:

<MTIfNonEmpty tag="entrydataassettest">
assettest: <MTentrydataassettest>
</MTIfNonEmpty>

The output of this code will look like:

assettest: View image

with the View image being a link to your asset.

In order to embed the image in the entry your code needs to look something like this:

<mt:EntryAssets>
<MTentrydataassettest>
<img src="<mt:AssetURL />" />
</mt:EntryAssets>
Carlo Laitano
Hey, it works great. After Arvind stop giving support for Custom Fields I was a bit lost with image assets and all but this cleared it up perfectly! Thanks for the post
raspberryh
Awesome, I totally needed this - thanks! smile.gif
blog-coding-is-fun
QUOTE (ghost robot @ Jan 27 2008, 09:31 AM) *
...
In order to embed the image in the entry your code needs to look something like this:

<mt:EntryAssets>
<MTentrydataassettest>
<img src="<mt:AssetURL />" />
</mt:EntryAssets>


OK, that's just what I needed! However, leaving "<MTentrydataassettest>" gives me the annoying link to the image, so I take it out, and it still works.


<mt:EntryAssets>
<img src="<mt:AssetURL />" />
</mt:EntryAssets>


...it still works. Um. Admittedly I only have one image attached to the entry, but I rather thought I'd have to tell the template which asset I wanted... Maybe I'll experiment with multiple assets later.

Your post also helped me find some related documentation; hopefully this is also helpful to others:
mt:Assets
Asset Template Tags

Thanks lots, ghost_robot!
blog-coding-is-fun
QUOTE (complex @ Jan 13 2009, 04:18 PM) *
... but I rather thought I'd have to tell the template which asset I wanted...


Nope! The above code will show all assets! If you add an image to the body of the article, that image is now one of the article's assets.

The mt:Assets page describes how to narrow down which image you want, but it seems to rely on you tagging your images with tags that your code will recognize. Not bad, and has some interesting potential applications, but not quite what I wanted.

After all, I have a special, custom field just for identifying the front page image. Is there a better way to use this specific, custom field instead of selecting from all of the article's assets?

(Not to downplay your answer, Ghost Robot, I'm just looking to continue on the same track.)
blog-coding-is-fun
QUOTE (complex @ Jan 14 2009, 09:31 AM) *
After all, I have a special, custom field just for identifying the front page image. Is there a better way to use this specific, custom field instead of selecting from all of the article's assets?


Ah, David gives us the answer in a post I tripped across completely by accident. This builds on what Ghost Robot found.

His example was for a custom field named "Image":

CODE
<MTIfNonEmpty tag="entrydatabig">
  <MTentrydatabigAsset>
    <img src="<$MTAssetURL$>" alt="" border="0" />
  </MTentrydatabigAsset>
</MTIfNonEmpty>


sorry to keep replying to myself, but I've been drinking coffee and working hard. I'm Rowdy Roddy Piper with no gum.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.