Question

I know that for a long time MT has not made it easy / accessible to edit the default markup that wraps an [image] asset when it is inserted into a MT entry. (So strange that this hasn't been created as a system module like everything else.)

There is one plugin that seemed to solve this problem, though it was written for MT 4* and seems to be defunct: https://github.com/endevver/mt-plugin-custom-asset-markup I've installed it, anyway, and it's unclear how it's supposed to work or be triggered / managed (there are no settings, though I may be doing it wrong).

Every time an image is inserted into an entry, I want its markup to include a few of its properties in the tag. For example, I want to assign the ID value of each image when it's inserted into the entry body:

<IMG ID="ar_<mt:AssetId>" … />
  • Has this problem been solved in MT 6? (I'm holding off a system upgrade till we launch as I don't want to destabilize right now, but might be worth it.)
  • Tips on how to operate the plugin above?
  • Any suggestions / hacks, other than editing the Perl modules directly or writing my own plugin?
Was it helpful?

Solution

I've used the Assetylene plugin to do this many times. It works just as you expect -- create a template module named "Asset Insertion" and edit the HTML to be spit out. I've tested it with MT4 and 5 -- I'm sure it works with 5.2.6 -- and it should work with MT6, too.

OTHER TIPS

I ended up just editing the Perl files. FTR the relevant portions are here:

lib/MT/Asset/Image.pm

New code is below. Essentially there are a few conditions that output blobs of HTML, per the options selected by the user when inserting an asset into an entry. I know nothing about Perl — but basically in each relevant case inserted the MT::Util::encode_html( $asset->id ) into the sprintf call, and used the %s thingy to insert the value of the ID into my HTML at the appropriate point.

(I also got rid of the ca 1999 onclick "open a popup" code — replaced it with properties that can be read with a to-be-written jquery call.)

        my $link
            = $thumb
            ? sprintf(
            '<img src="%s" %s alt="%s" %s id="aid_%s" />',
            MT::Util::encode_html( $thumb->url ),   $dimensions,
            MT::Util::encode_html( $asset->label ), $wrap_style,
            MT::Util::encode_html( $asset->id )
            )
            : MT->translate('View image');
        $text = sprintf(
            q|<a href="%s" class="popup" data-img-url="%s" data-img-width="%s" data-img-width="%s">%s</a>|,
            MT::Util::encode_html( $popup->url ),
            MT::Util::encode_html( $popup->url ),
            $asset->image_width,
            $asset->image_height,
            $link,
        );
    }
    else {
        if ( $param->{thumb} ) {
            $text = sprintf(
                '<a href="%s"><img alt="%s" src="%s" %s %s id="aid_%s" /></a>',
                MT::Util::encode_html( $asset->url ),
                MT::Util::encode_html( $asset->label ),
                MT::Util::encode_html( $thumb->url ),
                $dimensions,
            : MT->translate('View image');
        $text = sprintf(
            q|<a href="%s" class="popup" data-img-url="%s" data-img-width="%s" data-img-width="%s">%s</a>|,
            MT::Util::encode_html( $popup->url ),
            MT::Util::encode_html( $popup->url ),
            $asset->image_width,
            $asset->image_height,
            $link,
        );
    }
    else {
        if ( $param->{thumb} ) {
            $text = sprintf(
                '<a href="%s"><img alt="%s" src="%s" %s %s id="aid_%s" /></a>',
                MT::Util::encode_html( $asset->url ),
                MT::Util::encode_html( $asset->label ),
                MT::Util::encode_html( $thumb->url ),
                $dimensions,
                $wrap_style,
                MT::Util::encode_html( $asset->id )
            );
        }
        else {
            $text = sprintf(
                '<img alt="%s" src="%s" %s %s id="aid_%s" />',
                MT::Util::encode_html( $asset->label ),
                MT::Util::encode_html( $asset->url ),
                $dimensions, $wrap_style,
                MT::Util::encode_html( $asset->id ),
            );
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top