# $Id: EntryByID.pl,v 1.1 2003/03/04 22:32:13 akosut Exp $ # by Alexei Kosut # # is a container tag whose context is set to the entry # ID (or IDs, comma-seperated) in the id parameter. # # This will print the title of entry 57: # Entry 57 title: <$MTEntryTitle$> # # This will output "124 ": # <$MTEntryID$> use MT; use MT::Template::Context; use strict; use warnings; MT::Template::Context->add_global_filter(hr_section => sub { my ($s, $i) = @_; my @sections = split(/\s*\s*/, $s); return $sections[$i] || ""; }); use MT::Template::Context; use MT::Entry; use strict; MT::Template::Context->add_container_tag(EntryByID => sub { my ($ctx, $args) = @_; my $ids = $args->{'id'} or return $ctx->error("MTEntryByID: no id parameter"); my $builder = $ctx->stash('builder'); my $tokens = $ctx->stash('tokens'); my $res = ''; for my $id (split(',', $ids)) { my $entry = MT::Entry->load($id) or return $ctx->error("MTEntryByID: entry $id not found"); local $ctx->{__stash}{entry} = $entry; local $ctx->{current_timestamp} = $entry->created_on; my $out = $builder->build($ctx, $tokens); return $ctx->error( $builder->errstr ) unless defined $out; $res .= $out; } return $res; });