-
Notifications
You must be signed in to change notification settings - Fork 9
Applying Filters to Titles
djacobs edited this page Oct 3, 2011
·
6 revisions
Actually, this can be used to apply text filters to anything. In my Entry Summary and Entry Detail templates, I originally had this:
<h1><a href="<$MTEntryPermalink$>"><mt:entrytitle></a></h1>
Which works fine, but what I really wanted was to apply Smartypants to get proper punctuation. So I came up with this:
<mt:setvarblock name="markdown_title"># <a href="<$MTEntryPermalink$>"><mt:entrytitle></a></mt:setvarblock> <mt:getvar name="markdown_title" filters="markdown_with_smartypants">
Which does exactly what I want. It also means I could do things like add asterisks around words in a title to make them bold or italic.
Note, however, that if the data you're setting in <mt:setvarblock> is multiple lines, you'll need convert_breaks="0" on the tag where the original data comes from. Otherwise, it will have <p></p> tags added, and Markdown will skip their contents. For example: <mt:setvarblock name="comment"><$mt:CommentBody$></mt:setvarblock> <$mt:Var name="comment" filters="markdown_with_smartypants"$> ...will ignore the Markdown, showing the Markdown formatting characters instead of HTML markup. While: <mt:setvarblock name="comment"><$mt:CommentBody convert_breaks="0"$></mt:setvarblock> <$mt:Var name="comment" filters="markdown_with_smartypants"$> ...will work as expected, with Markdown adding paragraph breaks in addition to formatting markup. Likewise, removing paragraph tags from what's intended to be a single line of text can be done with this: <mt:setvarblock name="comment"><$mt:EntryTitle convert_breaks="0"$></mt:setvarblock> <h1><$mt:Var name="comment" filters="markdown_with_smartypants" regex_replace="/<\/?p>/g",""$></h1> That will produce a Markdown-formatted single line, without surrounding </p></mt:setvarblock> tags.