default userpic

Testing EntryExcerpt with mt:If

Vote 0 Votes

Logic to implement: If Entry has an excerpt, use it; if it does not, return content in EntryBody.

This produces weird results:
<mt:If tag="EntryExcerpt" />if entry has excerpt, return it<mt:Else>do something else</mt:If>

I've gone through several combinations, with and without auto_generate no_generate. Can anybody offer a solution?

Reported on Movable Type 4.2

8 Replies

| Add a Reply
  • Tried this yet?

    <mt:IfNonEmpty tag="EntryExcerpt">
    <$mt:EntryExcerpt$>
    <mt:Else>
    <$mt:EntryBody$>
    </mt:IfNonEmpty>

  • I considered this, but didn't touch IfNonEmpty, because it is documented as deprecated. Now that you mentioned it, I tried your code, and it returns the same result as simply using <mt:EntryExcerpt /> - that is, it will auto-generate an excerpt from EntryBody, if there is no excerpt.

    I think there was a time when your code worked. I suppose that EntryExcerpt got neglected ever since mt:If was given more powers.

    • Come to think of it, it probably never worked, since EntryExcerpt auto-generates and is therefore never empty. This logic might work better with a custom field.

      There was an interesting comment here by Jay Allen about the places EntryExcerpt is used.

      (I actually don't like to use it, since it strips html out, and there may be links at the beginning of the entry.)

      I also wish MT knew what a sentence or paragraph was.

      • Well, if you use <mt:If tag="EntryExcerpt" no_generate="1"> or the code in Dan Wolfgang's reply, then EntryExcerpt will evaluate to an empty value if there is no excerpt.

        A little correction on my post above: It should read no_generate, not "auto_generate".

      • What do you mean by "links at the beginning of the entry"?

        • strips html, so when we use it on a multiblog custom index template aggregating topical posts from many bloggers (e.g.on Inauguration Day), using EntryExcerpt to keep its length manageable strips html that's in those first n words.

  • You need to use the no_generate flag to get what you want: http://www.movabletype.org/documentation/appendices/tags/entryexcerpt.html

    <mt:EntryExcerpt no_generate="1" setvar="excerpt">
    <mt:If name="excerpt">
        <mt:EntryExcerpt>
    <mt:Else>
        <mt:EntryBody>
    </mt:If>
    
    • I must have overlooked something else earlier today, because this works and I used a variant (<mt:If tag="EntryExcerpt" no_generate="1">) without seeing the correct result. Thanks for your input.

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

695 2910

Last Topic: Insert Image / File Fails by Russ Miller on Feb 10, 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 567

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