Problems with MT:KeyValues
By Oli
At 2:16 PM · Sunday, 12 October · 2003
To Coding · Weblogging
I’m having problems with Brad Choate’s most excellent MT:KeyValues plugin. I presently use it to create better URLs for my articles (setup notes), by defining a KeyValue tag to replace the always-too-long dirified title as an informative file name/URL slug. The problem comes when I try to use a second KeyValues tag to determine whether I display the entry’s excerpt or the whole entry on my home page. Using this code I should be able to do it.
<MTKeyValues> <MTIfNoKeyExists key="more"><$MTEntryBody smarty_pants="1"$></MTIfNoKeyExists> <MTIfKeyExists key="more"><$MTEntryExcerpt smarty_pants="1"$><p class="cont"><a href="<$MTEntryPermalink$>" title="<$MTEntryTitle smarty_pants="1" remove_html="1"$>">Continued</a>... (<MTWordCount> words)</p></MTIfKeyExists> </MTKeyValues>
However the value for <$MTEntryPermalink$> in this code block is different to the same tag in the entry’s title.
<h2><a name="<$MTEntryID pad="1"$>"></a><a href="<$MTEntryPermalink$>" title="<$MTEntryTitle smarty_pants="1" remove_html="1"$>"><$MTEntryTitle smarty_pants="1"$></a></h2>
When the <$MTEntryPermalink$> variable isn’t in a <MTKeyValues> tag it uses the correct URL, but when it is it uses a dirified-equivalent URL, creating a link to a file that doesn’t exist. For the moment I’ve replaced the KeyValues code with:
<$MTEntryExcerpt smarty_pants="1"$> <p class="cont"><a href="<$MTEntryPermalink$>" title="<$MTEntryTitle smarty_pants="1" remove_html="1"$>">Continued</a>... (<MTWordCount> words)</p>
This only gives me a blanket excerpt-only listing of stories on my home page, but until I can find out what’s going wrong it will have to do. I’ve left my date archives with the faulty code, so if you’d like to see this problem in action, check out the October archive. Any help would be greatly appreciated!
Update
I’ve just received a reply from Brad himself, about 20 minutes after sending the email (!). He suggested replacing <$MTEntryPermalink$> with:
<$MTArchiveDate format="%Y/%m/%d"$>/<MTIfNoKeyExists key="url"><$MTEntryTitle dirify="1"$></MTIfNoKeyExists><MTIfKeyExists key="url"><MTKeyValue key="url"></MTIfKeyExists>
It works perfectly, and he’s investigating further. Thanks Brad!