Help - Search - Members - Calendar
Full Version: Adding a new date tag
Movable Type Community Forum > Additional Resources > Tips and Tricks
Georgina
QUOTE
%e
The day of the month, padded with a space if necessary. Example: 9.


I'd like to add another version of %e, perhaps %E, where the space used for padding is a non-breaking space character rather than just a space.  I start my category archives with the date first, and browsers tend to ignore a regular space at the beginning of a line, leading to a ragged format.

i.e.

13.09 :: Entry four.
1.09 :: Entry three
27.08 :: Entry two.
20.08 :: Entry one.

I realise I could use %d, but I prefer the format as shown above.

It seems as though it could be relatively easy to add a new date tag, but I can't find the right file to edit.  Can anybody point me in the right direction, or perhaps to a thread that already addresses this?

Thanks.
Georgina
Bueller?

Even a "You're dreaming, it's impossible" would be helpful, just so I'd know.
gabbro
Check out the function format_ts in Util.pm.

I wanted the month number padded by a space, as PHP plays wacky with the leading zeros produced by %m, so I added a line:
CODE
 $f{a} = substr $L->[0][$f{w}], 0, 3;
 $f{A} = $L->[0][$f{w}];
 ($f{e} = $f{d}) =~ s!^0! !;
 # crazy magic hack: %n gives month # padded with a space! whoa!
 ($f{n} = $f{m}) =~ s!^0! !;
 $f{I} = $f{H};
 $f{I} = $f{H};

It works beautifully. I don't really speak perl, so I can't go any further with what you want... but hopefully this is a starting point at least. smile.gif
bschoate
If you're using MT 2.21 and install the regex plugin, you can do this:
CODE
<MTEntryDate format="%e" regex="s/\s/&nbsp;/g">

That will translate any blanks to use the nbsp entity (but only where you specify to do so as shown above).
Georgina
QUOTE
It works beautifully. I don't really speak perl, so I can't go any further with what you want... but hopefully this is a starting point at least. :)


ahh.

That indeed was a starting point, thank you, gabbro. :)  I have it working now.

bschoate, I don't have the regex plugin installed, but thank you for providing another potential solution.
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-2010 Invision Power Services, Inc.