(apologies if this is documented somewhere that I missed)
I am trying to write a simple plugin. All I want to do is check an entry title against some criteria, and if a match is made display the entry.
I have written some Perl, and tested it at an OS level and it works. But I can not make it function within the MT framework.
This is a limitation on my part. Although I know a little Perl, I mainly use it for scripting, and data munging, and I do not have a very good grasp on OOP.
I have based the plugin on the MTEntryIfTitle in the documentation, but when I have added my conditional checking it does not perform as expected (it displays nothing, although the IfYes, and IfNo works fine).
A more detailed overview...
What I am trying to achieve is the ability to display entries based on title contect. I want to check the first 10 characters of a title (always in the same format) against the current date, and if the "title date" has passed then I do not want the entry displayed.
I know I can re-edit the authored date, but that seems to stick on entry ID number, and does not always sort correctly once edited. This is for use in displaying up and coming gigs for a local band.
Perl Code
CODE
use MT::Template::Context;
MT::Template::Context->add_conditional_tag(IfYes => sub { 1 });
MT::Template::Context->add_conditional_tag(IfNo => sub { 0 });
MT::Template::Context->add_conditional_tag(EntryIfTitle => sub { &_datecheck; });
sub _datecheck {
my $e = $_[0]->stash('entry');
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$isdst) = localtime();
my $RC=0;
if (length(++$mon) eq 1){$mon="0".$mon;}
$year=$year+1900;
if (length($mday) eq 1){$mday="0".$mday;}
if ( $e =~ /^[0-9]{4}\-[0-9]{2}\-[0-9]{2}.*$/ )
{ if (substr($e,0,10) ge "$year-$mon-$mday" ) { $RC=1; } }
return $RC;
}
1;
MT::Template::Context->add_conditional_tag(IfYes => sub { 1 });
MT::Template::Context->add_conditional_tag(IfNo => sub { 0 });
MT::Template::Context->add_conditional_tag(EntryIfTitle => sub { &_datecheck; });
sub _datecheck {
my $e = $_[0]->stash('entry');
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$isdst) = localtime();
my $RC=0;
if (length(++$mon) eq 1){$mon="0".$mon;}
$year=$year+1900;
if (length($mday) eq 1){$mday="0".$mday;}
if ( $e =~ /^[0-9]{4}\-[0-9]{2}\-[0-9]{2}.*$/ )
{ if (substr($e,0,10) ge "$year-$mon-$mday" ) { $RC=1; } }
return $RC;
}
1;
...and the HTML...
CODE
<MTEntries category="gigs">
<MTEntryIfTitle>
This entry has a title: <$MTEntryTitle$><br>
</MTEntryIfTitle>
</MTEntries>
<MTEntryIfTitle>
This entry has a title: <$MTEntryTitle$><br>
</MTEntryIfTitle>
</MTEntries>
I appreciate that I might be going around this the long/wrong way, but I want to prove to myself I can do it!
Thanks in Advance,
Jon.