Más contenido relacionado
Similar a やはりお前らのMTMLは間違っている! (12)
やはりお前らのMTMLは間違っている!
- 24. Perl
sub main_hdlr {!
my $x = 1;!
my $y = 2;!
print sub_hdlr( $x, $y );!
$x;!
}!
!
sub sub_hdlr {!
my ( $value1, $value2 ) = @_;!
my $x = $value1 + $value2;!
return $x;!
}
<= 1
<= 3
- 28. Movable Type
<mt:Setvar name="x" value="1">!
<mt:Setvar name="y" value="1">!
!
<mt:LocalVars>!
<mt:Setvar name="x" value="$y" op="+">!
<mt:Var name="x">!
</mt:LocalVars>!
!
<mt:Var name="x">!
!
<= 2
<= 1
変数を局所化する
- 33. <mt:Setvar name="show_entries_counter" value="0">!
<mt:Entries>!
<mt:EntryKeywords setvar="entry_keywords">!
<mt:EntryTitle setvar="entry_title">!
<mt:EntryBody setvar="entry_body">!
<mt:If name="entry_keywords" like="東京">!
<mt:If name="entry_title" like="東京">!
<mt:If name="entry_body" like="MTDDC">!
<mt:If name="show_entries_counter" lt="10">!
<mt:Unless name="show_entries_counter">!
<ul>!
</mt:Unless>!
<li><mt:EntryTitle></li>!
<mt:Setvar name="show_entries_counter"!
op="++" setvar="show_entries_counter">!
</mt:If>!
</mt:If>!
</mt:If>!
</mt:If>!
<mt:If name="show_entries_counter" eq="10">!
</ul>!
</mt:If>!
</mt:Entries>
ロジック=>
ロジック=>
ビュー=>
テンプレート1
- 34. <mt:Setvar name="show_entries_counter" value="0">!
<mt:Entries>!
<mt:EntryKeywords setvar="entry_keywords">!
<mt:EntryTitle setvar="entry_title">!
<mt:EntryBody setvar="entry_body">!
<mt:SetVar name="show_entry" value="0">!
<mt:If name="entry_keywords" like="東京">!
<mt:If name="entry_title" like="東京">!
<mt:If name="entry_body" like="MTDDC">!
<mt:If name="show_entries_counter" lt="10">!
<mt:SetVar name="show_entry" value="1">!
<mt:Setvar name="show_entries_counter" !
op="++" setvar="show_entries_counter">!
</mt:If>!
</mt:If>!
</mt:If>!
</mt:If>!
<mt:If name="show_entry">!
<mt:Unless name="show_entries_counter"><ul></mt:Unless>!
<li><mt:EntryTitle></li>!
<mt:Setvar name="show_entries_counter"!
op="++" setvar="show_entries_counter">!
</mt:If>!
<mt:If name="show_entries_counter" eq="10">!
</ul>!
</mt:If>!
</mt:Entries>
ロジック=>
ビュー=>
テンプレート2
- 35. <mt:Setvar name="show_entries_counter" value="0">!
<mt:Entries>!
<mt:EntryKeywords setvar="entry_keywords">!
<mt:EntryTitle setvar="entry_title">!
<mt:EntryBody setvar="entry_body">!
<mt:SetVar name="show_entry" value="0">!
<mt:If name="entry_keywords" like="東京">!
<mt:If name="entry_title" like="東京">!
<mt:If name="entry_body" like="MTDDC">!
<mt:If name="show_entries_counter" lt="10">!
<mt:EntryId setvar="entry_id">!
<mt:SetVar name="entry_ids"!
function="push" value="$entry_id">!
<mt:Setvar name="show_entries_counter" !
op="++" setvar="show_entries_counter">!
</mt:If>!
</mt:If>!
</mt:If>!
</mt:If>!
</mt:Entries>
ロジックのみ=>
前半
テンプレート3
- 36. <mt:Entries entry_ids="$entry_ids">!
<mt:If name="__first__"><ul class="entries_widget"></mt:If>!
<li class="<mt:If name="__odd__">odd!
<mt:Else>even</mt:If>">!
<a href="<mt:EntryPermalink>">!
<mt:EntryTitle escape="html">!
</a>!
<span class="date"><mt:EntryDate></span>!
<p class="description">!
<mt:EntryExcerpt remove_html="1">!
</p>!
</li>!
<mt:If name="__last__">!
</ul>!
</mt:If>!
</mt:Entries>!
ビューのみ=>
後半
テンプレート3
entry_idsはGetHashVarプラグインが
提供するモディファイア
- 37. <mt:Setvar name="show_entries_counter" value="0">!
<mt:Entries>!
<mt:EntryKeywords setvar="entry_keywords">!
<mt:EntryTitle setvar="entry_title">!
<mt:EntryBody setvar="entry_body">!
<mt:SetVar name="show_entry" value="0">!
<mt:If name="entry_keywords" like="東京">!
<mt:If name="entry_title" like="東京">!
<mt:If name="entry_body" like="MTDDC">!
<mt:If name="show_entries_counter" lt="10">!
<mt:SetHashVars name="cols">!
title=<mt:EntryTitle>!
excerpt=<mt:EntryExcerpt>!
date=<mt:EntryDate>!
permalink=<mt:EntryPermalink>!
</mt:SetHashVars>!
<mt:SetVar name="entries"!
function="push" key="$__counter__" value="$cols">!
<mt:Setvar name="show_entries_counter" !
op="++" setvar="show_entries_counter">!
</mt:If>!
</mt:If>!
</mt:If>!
</mt:If>!
</mt:Entries>
ロジックのみ=>
テンプレート4
前半
SetHashVarsはGetHashVarプラグインが提供
(setHashVarタグ使えば標準機能だけでも可能)
<= 変数にハッシュで格納
- 38. <mt:Loop name="entries">!
<mt:If name="__first__"><ul class="entries_widget"></mt:If>!
<li class="<mt:If name="__odd__">odd!
<mt:Else>even</mt:If>">!
<a href="<mt:Var name="__value__{permalink}">">!
<mt:Var name="__value__{title}" escape="html">!
</a>!
<span class="date">!
<mt:Var name="__value__{date}"></span>!
<p class="description">!
<mt:Var name="__value__{excerpt}"!
remove_html="1">!
</p>!
</li>!
<mt:If name="__last__">!
</ul>!
</mt:If>!
</mt:Loop>!
ビューのみ=>
テンプレート4
後半
ただし、変数は諸刃の件。ググれないし、定義した⼈にしかわからないから。
- 46. CakePHPのView
<table>!
<tr>!
<th>Id</th>!
<th>Title</th>!
<th>Created</th>!
</tr>!
<!-- Here is where we loop through our $posts array, printing
out post info -->!
<?php foreach ($posts as $post): ?>!
<tr>!
<td><?php echo $post['Post']['id']; ?></td>!
<td>!
<?php echo $html->link($post['Post']['title'], !
array('controller' => 'posts', 'action' => 'view', $post['Post']
['id'])); ?>!
</td>!
<td><?php echo $post['Post']['created']; ?></td>!
</tr>!
<?php endforeach; ?>!
</table>!
- 47. MTCakeのView
<mt:cake:loop model="Post">!
<mt:ignore>!
or <mt:cake:loop model="Post" stash="posts">!
</mt:ignore>!
<mt:if name="__first__">!
<table>!
<tr>!
<th>Id</th>!
<th>Title</th>!
<th>Created</th>!
</tr>!
</mt:if>!
<tr>!
<td><mt:var name="id"></td>!
<td>!
<a href="./view/<mt:var name="id">"><mt:var name="title"
escape="html"></a>!
</td>!
<td><mt:var name="created"></td>!
</tr>!
<mt:if name="__last__">!
</table>!
</mt:if>!
</mt:cake:loop>!
- 48. <?php foreach ($posts as $post): ?>!
<tr>!
<td><?php echo $post['Post']['id']; ?></td>
<mt:cake:loop model="Post">!
<tr>!
<td><mt:var name="id"></td>
モデルを変えれば書き⽅は同じ、同じ振るまい
- 58. <mt:setVarBlock name="search1">/<lz:/g</mt:setVarBlock>!
<mt:setVarBlock name="replace1"><</mt:setVarBlock>!
<mt:setVarBlock name="replace1" append="1">mt:</mt:setVarBlock>!
!
<mt:setVarBlock name="search2">/</lz:/g</mt:setVarBlock>!
<mt:setVarBlock name="replace2"><</mt:setVarBlock>!
<mt:setVarBlock name="replace2" append="1">/mt:</mt:setVarBlock>!
!
<mt:Unless regex_replace="$search1","$replace1"!
regex_replace="$search2","$replace2" mteval="1">!
!
<lz:Entries <mt:If name="want_filter">field:foo="1"</mt:if>>!
<lz:If name="__first__"><ul></lz:If>!
<li><lz:EntryTitle></li>!
<lz:If name="__last__"></ul></lz:If>!
</lz:Entries>!
</mt:Unless>
テンプレート2
- 64. mt:Includeのblog_idに変数を使うのは?
<mt:Include module="HTMLヘッダー" blog_id="$blog_id">
こう書きたい理由は? 開発環境と本番環境でblog_idが違う?
<mt:If name="config.IsProduction">!
<mt:Include module="HTMLヘッダー" blog_id="2">!
<mt:Else>!
<mt:Include module="HTMLヘッダー" blog_id="$blog_id">!
</mt:If>!
もしくは
<mt:Unless name="config.IsProduction">!
<mt:GetElementById id="html_header" setvar="html_header">!
<mt:SetAttribute node="html_header" attributes=„blog_id","$blog_id">!
</mt:Unless>!
<mt:Include module="HTMLヘッダー" blog_id="2" id="html_header">!
- 66. コメントはどこに⼊れたらいい?
<mt:Ignore>第1条件</mt:Ignore>!
<mtSetvar name="ad_attr" function="push" value="area" note="地域">!
<mtSetvar name="add_condition" function="push" value="STREQ" note="等しい">!
<mtSetvar name="values" function="push" value="江東区" note="江東区">!
!
<mt:Ignore>第2条件</mt:Ignore>!
<mtSetvar name="ad_attr" function="push" value="station" note="駅">!
<mtSetvar name="add_condition" function="push" value="STRINC" note="含む">!
<mtSetvar name="values" function="push" value="森下" note="森下">!
!
<mt:EstraierSearch !
ad_attr="$ad_attr" add_condition="$add_condition" values="$values">!
# do something.!
</mt:EstraierSearch>
存在しないモディファイアは無視される
- 68. MTEntriesとMTPagesを共通化したい
<mt:If name="archive_type" eq="Individual">!
<mt:Entries>!
<mt:SetHashVars name="cols">!
title=<mt:EntryTitle>!
excerpt=<mt:EntryExcerpt>!
date=<mt:EntryDate>!
permalink=<mt:EntryPermalink>!
</mt:SetHashVars>!
<mt:SetVar name="entries"!
function="push" key="$__counter__" value="$cols">!
</mt:Entries>!
<mt:Elseif name="archive_type" eq="Page">!
<mt:Pages>!
<mt:SetHashVars name="cols">!
title=<mt:PageTitle>!
excerpt=<mt:PageExcerpt>!
date=<mt:PageDate>!
permalink=<mt:PagePermalink>!
</mt:SetHashVars>!
<mt:SetVar name="entries"!
function="push" key="$__counter__" value="$cols">!
</mt:Pages>!
</mt:If>!
<mt:Loop name="entries">!
# do something.!
</mt:Loop>