21-3 拡張テンプレートタグ
405ページ
config.yaml
tags:
block:
Examples: $Example::Example::Tags::_hdlr_examples
ifExample: $Example::Example::Tags::_hdlr_if_example
function:
ExampleName: $Example::Example::Tags::_hdlr_example_name
modifier:
add_example: $Example::Example::Tags::_fltr_add_example
406ページ
<mt:Templates>
<mt:ifTemplateTypeIndex>
<mt:TemplateName />
</mt:ifTemplateTypeIndex>
</mt:Templates>
config.yaml
name: Templates
id: Templates
description: This plugin is an example plugin.
version: 0.01
tags:
block:
Templates: $Templates::Templates::Tags::_hdlr_templates
ifTemplateTypeIndex?: $Templates::Templates::Tags::_hdlr_if_template_type_index
function:
TemplateName: $Templates::Templates::Tags::_hdlr_template_name
Tags.pm
package Templates::Tags;
use strict;
sub _hdlr_templates {
my ($ctx, $args, $cond) = @_;
my ($terms, $args);
$terms->{ blog_id } = $ctx->stash('blog_id');
$args->{ sort } = 'name';
my $iter = MT::Template->load_iter( $terms, $args );
my $res = '';
my $tokens = $ctx->stash('tokens');
my $builder = $ctx->stash('builder');
while (my $tmpl = $iter->()) {
local $ctx->{__stash}{tmpl} = $tmpl;
defined(my $out = $builder->build($ctx, $tokens, $cond)) or
return $ctx->error( $builder->errstr );
$res .= $out;
}
$res;
}
sub _hdlr_if_template_type_index {
my ($ctx, $args) = @_;
my $tmpl = $ctx->stash('tmpl')
or return _error($ctx, 'MT'.$ctx->stash('tag'));
return $tmpl->type =~ /index/;
}
sub _hdlr_template_name {
my ($ctx, $args) = @_;
my $tmpl = $ctx->stash('tmpl')
or return _error($ctx, 'MT'.$ctx->stash('tag'));
$tmpl->name;
}
sub _error {
my ($ctx, $tag) = @_;
$ctx->error(MT->translate
('You used an [_1] tag outside of the proper context.', $tag));
}
1;
410ページ
config.yaml
name: AddLink
id: AddLink
description: This plugin is an example plugin.
version: 0.01
tags:
modifier:
add_link: $AddLink::AddLink::Tags::_fltr_add_link
Tags.pm
package AddLink::Tags;
use strict;
sub _fltr_add_link {
my ($str, $arg, $ctx) = @_;
return '<a href="' . $arg . '">' . $str . '</a>';
}
1;
411ページ
tags:
block:
Entries: $Example::Example::Tags::_hdlr_entries_overload
function:
EntryTitle: $Example::Example::Tags::_hdlr_entry_title_overload