Movable Type/Â裱£¶²óMT¥×¥é¥°¥¤¥óÊÙ¶¯²ñ - MT-Template-Context¡¢stash¤È¥³¥ó¥Æ¥Ê¡¦¥¿¥°¤ÎºîÀ® http://www.ark-web.jp/sandbox/wiki/1933.html
Movable Type/Â裱£¶²óMT¥×¥é¥°¥¤¥óÊÙ¶¯²ñ - MT-Template-Context¡¢stash¤È¥³¥ó¥Æ¥Ê¡¦¥¿¥°¤ÎºîÀ®
Â裱£¶²ó¤ÏMT::Template::Context¥¯¥é¥¹¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤òÆɤߡ¢stash¤Î°·¤¤Êý¤È¡¢¥³¥ó¥Æ¥Ê¡¦¥¿¥°¤ÎºîÀ®ÊýË¡¤Ë¤Ä¤¤¤Æ¼è¤ê¾å¤²¤Þ¤¹¡£
Æ°²è¡ÊUstream¡Ë †
ÊÙ¶¯²ñ¤ÎÌÏÍͤò¥¢¥Ã¥×¤·¤Þ¤·¤¿¡£
Ustream¤Î¥Á¥ã¥ó¥Í¥ë¤Ï¤³¤Á¤é¡£
http://www.ustream.tv/channel/mt%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E5%8B%89%E5%BC%B7%E4%BC%9A
¥³¥ó¥Æ¥Ê¡¦¥¿¥°¤Îºî¤êÊý †
¥³¥ó¥Æ¥Ê¡¦¥¿¥°¤È¤Ï¡© †
Movable Type ¥ª¥Ö¥¸¥§¥¯¥È¡¦¥ê¥Õ¥¡¥ì¥ó¥¹ - MT::Template::Context¤è¤ê¡£
¥³¥ó¥Æ¥Ê¡¦¥¿¥°¤Ï°ìÈÌŪ¤Ë¥ë¡¼¥×¤ò¼Â¸½¤¹¤ë¤¿¤á¤ËÍѤ¤¤Þ¤¹¡£
¤Ä¤Þ¤ê¡¢<MTEntries>¤Î¤è¤¦¤Ë¡¢¤½¤ÎÆ⦤Ëʸ»úÎó¡¢HTML¥¿¥°¤äMT¥Æ¥ó¥×¥ì¡¼¥È¥¿¥°¤ò´Þ¤à¤³¤È¤¬¤Ç¤¤ë¥Ö¥í¥Ã¥¯¤òɽ¸½¤·¡¢¤µ¤é¤Ë¥ë¡¼¥×¤â¼Â¸½¤Ç¤¤ë¤â¤Î¤Ç¤¹¡£Î㤨¤Ð<MTEntries>¤Ç¤Ï
<MTEntries> ¥¿¥¤¥È¥ë¤Ï<$MTEntryTitle$>¤Ç¤¹¡£ </MTEntries>
¤Ç¥¨¥ó¥È¥ê¡¼¤ò·«¤êÊÖ¤·¡Ê¥ë¡¼¥×¤·¡Ë¡¢¤½¤Î¥¿¥¤¥È¥ë¤òɽ¼¨¤·¤Þ¤¹¡£
stash¤È¤Ï¡© †
¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢¥×¥é¥°¥¤¥óÃæ¤Ç¡¢°Û¤Ê¤ë¥¿¥°¤Î¸Æ¤Ó½Ð¤·¤Î´Ö¤Ç¤ä¤ê¼è¤ê¤¹¤ë¥Ç¡¼¥¿¤ò³ÊǼ¤¹¤ë¥·¥ó¥×¥ë¤Ê¥¹¥¿¥Ã¥·¥å¤ÎÆɤ߽ñ¤¤ò¹Ô¤¤¤Þ¤¹¡£¤¿¤È¤¨¤Ð¡¢¾å½Ò¤Î<MTLoop>¥¿¥°¤Î¼ÂÁõÎã¤Ë¼¨¤·¤¿¤è¤¦¤Ë¡¢¥³¥ó¥Æ¥Ê¡¦¥¿¥°¤ò¼ÂÁõ¤¹¤ëºÝ¤ËÍÍѤǤ¹¡£ $key¤Ï¥¹¥¿¥Ã¥·¥å¤ò¼±Ê̤¹¤ë¤¿¤á¤Î¥¹¥«¥é¡¼Ê¸»úÎó¤Ç¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£$value¤ò»ØÄꤹ¤ë¾ì¹ç¡¢Ç¤°Õ¤Î¥¹¥«¥é¡¼ÃÍ¡Êʸ»úÎ󡢿ôÃÍ¡¢¥ê¥Õ¥¡¥ì¥ó¥¹¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Ê¤É¡Ë¤¬»ØÄê²Äǽ¤Ç¤¹¡£ $key¤Î¤ß¤ò»ØÄꤷ¤Æ¤³¤Î¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤¹¤È¡¢$key¤È¤¤¤¦¥¡¼¤Ç¥¹¥¿¥Ã¥·¥å¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ëÃͤ¬ÊÖ¤µ¤ì¤Þ¤¹¡£$key¤È$value¤ÎξÊý¤ò»ØÄꤷ¤¿¾ì¹ç¡¢$key¤Î¥¹¥¿¥Ã¥·¥å¤ÎÃͤò$value¤ËÀßÄꤷ¤Þ¤¹¡£
MT::Template::Context¥ª¥Ö¥¸¥§¥¯¥È¤¬Ä󶡤¹¤ëstash¥á¥½¥Ã¥É¤Ï¥Æ¥ó¥×¥ì¡¼¥È½èÍý»þ¤ÎǤ°Õ¤Î¥¹¥Æ¡¼¥¿¥¹¤òÊÝ»ý¤·¤Þ¤¹¡£¤³¤ì¤Ï¥Æ¥ó¥×¥ì¡¼¥È½èÍýÃæ¤ÎÄê¿ô¡¢ÊÑ¿ô¡¢¥ª¥Ö¥¸¥§¥¯¥È¤ÎÊݸÎΰè¤È¤·¤ÆÍøÍѤ¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
# MT::Hoge¥ª¥Ö¥¸¥§¥¯¥È¤òºîÀ®¤·¤Æ¡¢stash¤ÎMyPlugin::Hoge¤ÇÊݸ¤·¤Æ¤ª¤¯¡£ my $hoge = new MT::Hoge; $ctx->stash('MyPlugin::Hoge', $hoge); ... # ¤½¤Î¸å¤É¤³¤«¤Ç¡ÊÊ̤Υ᥽¥Ã¥ÉÆâ¤Ç¤Ç¤â¡Ëstash¤«¤éÊݸ¤·¤Æ¤ª¤¤¤¿MT::Hoge¥ª¥Ö¥¸¥§¥¯¥È¤ò¼èÆÀ¤¹¤ë sub some_method { : my $hoge = $ctx->stash('MyPlugin::Hoge'); }
¤³¤Î¤è¤¦¤Ë¡¢¥×¥é¥°¥¤¥óÆâÉô¤ÇÆȼ«¤Ëstash¤ËÊݸ¤¹¤ë¾ì¹ç¤Ï¡¢key̾¤Ë¤Ï¥×¥é¥°¥¤¥ó̾¤ò¥×¥ì¥Õ¥£¥Ã¥¯¥¹¤È¤·¤Æ¤Ä¤±¤Æ¡ÊMyPlugin::¡Ë¾¤Î¥×¥é¥°¥¤¥ó¤È¥Ð¥Ã¥Æ¥£¥ó¥°¤·¤Ê¤¤¤è¤¦¤Ë¤·¤Þ¤¹¡£
¤Þ¤¿¡¢½èÍýÃæ¤Î¥¨¥ó¥È¥ê¡¼¤Ê¤É¡¢´ûÄê¤Î<type>¤Î¥ª¥Ö¥¸¥§¥¯¥È¡Ê<type>¤Ïentry¡¢category¤Ê¤É¡¢MT::*¡ÊMT::Object¤Î¥µ¥Ö¥¯¥é¥¹¡Ë¤òÆÃÄꤹ¤ë¼±Ê̻ҡˤò¼èÆÀ¤¹¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£
# ¸½ºß½èÍýÂоݤÎMT::Entry¥ª¥Ö¥¸¥§¥¯¥È¤òÆÀ¤ë¡£¥¨¥ó¥È¥ê¡¼¤ËÂФ·¤Æ½èÍý¤·¤Æ¤¤¤Ê¤±¤ì¤Ð¡Ê¡ástash¤ÎÊÖ¤êÃͤ¬null¤Ê¤é¡Ëreturn $ctx->stash('entry') or return;
¤³¤Î¤è¤¦¤Ë¡¢¼ÂºÝ¤Ë»ØÄꤷ¤¿<type>¤Î¥ª¥Ö¥¸¥§¥¯¥È¤¬¥í¡¼¥É¤Ç¤¤ë¤«¤É¤¦¤«¤Ïstash¥á¥½¥Ã¥É¤ò¸Æ¤ó¤Ç¡¢¤½¤ÎÊÖ¤êÃͤÇȽÃǤ¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£¤Ä¤Þ¤ê¡¢stash¥á¥½¥Ã¥ÉÍøÍѼԤ¬¥³¥ó¥Æ¥¥¹¥È¤ò°Õ¼±¤·¤Æ»È¤¦É¬Íפ¬¤¢¤ê¤Þ¤¹¡£
¤Ê¤ª¡¢¥³¥ó¥Æ¥Ê¡¦¥¿¥°¤Î¥Ï¥ó¥É¥é¥á¥½¥Ã¥ÉÆâ¤Ç¤Ï$ctx->stash('tokens')¡¢$cts->stash('builder')¤Ï¸ºß¤¬Êݾ㤵¤ì¤Æ¤¤¤Þ¤¹¡£
Movable Type ¥ª¥Ö¥¸¥§¥¯¥È¡¦¥ê¥Õ¥¡¥ì¥ó¥¹ - MT::Template::Context¤è¤ê
¥³¥ó¥Æ¥Ê¡¦¥¿¥°¤Ï°ìÈÌŪ¤Ë¥ë¡¼¥×¤ò¼Â¸½¤¹¤ë¤¿¤á¤ËÍѤ¤¤Þ¤¹¡£¤³¤Î¤¿¤á¡¢¥µ¥Ö¥ë¡¼¥Á¥óÆâ¤Ç¤Ï¡¢²¿¤é¤«¤ÎÍ×Áǥꥹ¥È¤Ë´Ø¤·¤Æ¥ë¡¼¥×¤µ¤»¤ë¥ë¡¼¥×¹½Â¤¤òÍÑ°Õ¤·¡¢¥³¥ó¥Æ¥Ê¡¦¥¿¥°¤ÎÆ⦤ǡ¢³ÆÍ×ÁǤËÂФ¹¤ëɽ¼¨¤ò¹Ô¤¦¤è¤¦¤Ê¥Æ¥ó¥×¥ì¡¼¥È¥¿¥°¤òÍÑ°Õ¤¹¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£¤³¤¦¤·¤¿Æ⦤Υƥó¥×¥ì¡¼¥È¥¿¥°¤Ï¡¢¥È¡¼¥¯¥ó¡¦¥ê¥¹¥È¤È¤·¤Æ¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤Æ¤¤¤ë¤¿¤á¡¢MT::Builder¥ª¥Ö¥¸¥§¥¯¥È¤òÍѤ¤¤ë¤À¤±¤Ç¡¢¤³¤Î¥È¡¼¥¯¥ó¡¦¥ê¥¹¥È¤ò¥¹¥«¥é¡¼Ê¸»úÎó¤ËÊÑ´¹¤·¡¢½ÐÎϤËÄɲ乤뤳¤È¤¬¤Ç¤¤Þ¤¹¡£¥È¡¼¥¯¥ó¤Î¥ê¥¹¥È¤Ï$ctx->stash('tokens')¤Ë³ÊǼ¤µ¤ì¡¢MT::Builder¥ª¥Ö¥¸¥§¥¯¥È¤Ï$ctx->stash('builder')¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
¥µ¥ó¥×¥ë¡¢²òÀâ †
¥³¥ó¥Æ¥Ê¡¦¥¿¥°¤ÎÅÐÏ¿¤Ï
MT::Template::Context->add_container_tag($name, \&subroutine)
¤Ç¹Ô¤¦¡£
Movable Type ¥ª¥Ö¥¸¥§¥¯¥È¡¦¥ê¥Õ¥¡¥ì¥ó¥¹ - MT::Template::Context¤è¤ê
$name¤Ë¤Ï¥¿¥°Ì¾¡ÊMT¥×¥ì¥Õ¥£¥¯¥¹¤ò½ü¤¤¤¿¤â¤Î¡Ë¤ò»ØÄꤷ¡¢\&subroutine¤Ë¤Ï̵̾¤Þ¤¿¤Ï̾Á°¤Ä¤¥µ¥Ö¥ë¡¼¥Á¥ó¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹¤ò»ØÄꤷ¤Þ¤¹¡£
¤Ç¤¹¡£
°Ê²¼¤Ë¡¢<MTMyLoop>¤Î¥³¥ó¥Æ¥Ê¡¦¥¿¥°¤òÄêµÁ¤·¡¢¤Þ¤¿¤½¤ÎÃæ¤Ç<MTMyCount>¤Ç²¿²óÌܤΥ롼¥×¤«¤òɽ¼¨¤¹¤ë¥µ¥ó¥×¥ë¤òµ½Ò¤·¤Þ¤¹¡£
¥Æ¥ó¥×¥ì¡¼¥È¥µ¥ó¥×¥ë
<MTMyLoop count="10"> ¥ë¡¼¥×¡¢<$MTMyCount$>²óÌÜ¤Î¼Â¹Ô </MTMyLoop>
¥×¥é¥°¥¤¥ó¥³¡¼¥É¡¢¥µ¥ó¥×¥ë
MT::Template::Context->add_container_tag('MyLoop', \&_my_loop); MT::Template::Context->add_tag('MyCount', \&_my_count); sub _my_loop { # ¥Ï¥ó¥É¥é¤Ë¤ÏÆó¤Ä¤Î°ú¿ô¤¬ÅϤµ¤ì¤ë¡£ # $ctx¤Ï¥Æ¥ó¥×¥ì¡¼¥ÈÀ¸À®»þ¤ËÍѤ¤¤¿MT::Template::Context¥ª¥Ö¥¸¥§¥¯¥È # $args¤Ï¥Æ¥ó¥×¥ì¡¼¥ÈÃæ¤Î¥¿¥°¤«¤éÅϤµ¤ì¤ë°ú¿ô¤ò³ÊǼ¤¹¤ë¥Ï¥Ã¥·¥åÇÛÎó¤Ø¤Î¥ê¥Õ¥¡¥ì¥ó¥¹ my $ctx = shift; my $args = shift; # ¥ë¡¼¥×²ó¿ô¤ò¼èÆÀ my $count = $args->{count} || 1; my $res = ''; my $builder = $ctx->stash('builder'); my $tokens = $ctx->stash('tokens'); for (my $i=1; $i<=$count; $i++) { $ctx->stash('MyLoop::index', $i); defined(my $out = $builder->build($ctx, $tokens)) or return $ctx->error($builder->errstr); $res .= $out; } return $res; } sub _my_count { my $ctx = shift; $ctx->stash('MyLoop::index'); }
$builder->build¥á¥½¥Ã¥É¤¬¼ºÇÔ¤·¤Æ¡¢½ÐÎϤι½ÃÛ¤¬¤Ç¤¤Ê¤«¤Ã¤¿»þ¤Ï$builder->errstr¤ÇÆÀ¤é¤ì¤ë¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤ò$ctx->error¤ÇÊÖ¤·¤Þ¤¹¡£
Movable Type ¥ª¥Ö¥¸¥§¥¯¥È¡¦¥ê¥Õ¥¡¥ì¥ó¥¹ - MT::Template::Context¤è¤ê
¥×¥é¥°¥¤¥óÆâ¤Î¥µ¥Ö¥ë¡¼¥Á¥ó¥Ï¥ó¥É¥é¤Ç¥¨¥é¡¼¤¬À¸¤¸¤¿¾ì¹ç¡¢¼¡¤Î¤è¤¦¤Ë*$ctx*¥ª¥Ö¥¸¥§¥¯¥È¤Î*error*¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤·¤Æ¥¨¥é¡¼¤òÊÖ¤¹É¬Íפ¬¤¢¤ê¤Þ¤¹¡£ return $ctx->error("the error message"); Æäˡ¢ÆÃÄê¤Î¥³¥ó¥Æ¥¥¹¥ÈÆâ¤Ç¸Æ¤Ó½Ð¤¹¤³¤È¤òÁ°Äó¤È¤¹¤ë¥¿¥°¤Ë¤Ä¤¤¤Æ¤Ï¡¢¤³¤Î¥á¥½¥Ã¥É¤òÍѤ¤¤ë¤³¤È¤¬¤è¤¯¤¢¤ê¤Þ¤¹¡£¤¿¤È¤¨¤Ð<$MTEntry*$>¥¿¥°¤Ï¤¹¤Ù¤Æ¡¢¥³¥ó¥Æ¥¥¹¥ÈÃæ¤Ë¥¨¥ó¥È¥ê¤¬Â¸ºß¤¹¤ë¤³¤È¤òÁ°Äó¤È¤·¤Æ¤¤¤Þ¤¹¡£ my $entry = $ctx->stash('entry') or return $ctx->error("Tag called without an entry in context"); ¤Èµ½Ò¤¹¤ë¤³¤È¤Ë¤è¤ê¡¢¥¨¥ó¥È¥ê¤¬Â¸ºß¤·¤Ê¤¤¥³¥ó¥Æ¥¥¹¥È¤Ç¤Î¸Æ¤Ó½Ð¤·»þ¤Ë¥¨¥é¡¼¤òÊÖ¤¹¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
¼¡²óͽÄê †
MT::Task¡¢MT::TaskMgr¤òÄ´¤Ù¤Æ¡¢MT¤Ç¤Î¥¿¥¹¥¯¥¹¥±¥¸¥å¡¼¥ë´ÉÍý¤ÎÊýË¡¤ò¼è¤ê¾å¤²¤¿¤¤¤È»×¤¤¤Þ¤¹¡£
tag: Movable Type¡¢MT¡¢MTPlugin¡¢ÊÙ¶¯²ñ