<sdl.block> タグを使ってブロックを定義し、<sdl.include> タグを使って呼び出す方法を学習しました。<sdl.function> タグを使って関数を定義する方法を学習します。関数には、ブロックとは異なり、定義時に実行されないという特徴があります。
sdl=com.traction.sdl.tutorial.lesson14
<sdl.function> ではなく <sdl.block> が使われていますが、レッスン 13 で学習したブロックとの違いを見るため、意図的に使用しています。
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>SDL Tutorial</title>
<html.css url="/html/css/sdllessons/styles.css" />
</head>
<body>
<h1>SDL 関数</h1>
<h2>記事リスト (1)</h2>
<!--- レッスン14では関数を扱いますが、
ブロックとの違いをまずは学習すしましょう。
この部分を「hoge」という名前のブロックにします。 -->
<sdl.block name="hoge">
<entries type="rchron" proj="*" max="5">
<loop.first><ul></loop.first>
<li>__entry.tractionid__ : __entry.title__</li>
<loop.last></ul></loop.last>
</entries>
</sdl.block>
<h2>記事リスト (2)</h2>
<!--- 「hoge」を呼び出して再利用します。 -->
<#hoge />
</body>
</html>
/type lesson14 と入力して Enter キーを押すと、下図のような「SDL ブロック」ビューが表示されます。画面には、レッスン 13 と同じく、記事リストが 2 つ表示されます。<sdl.block name="hoge">...</sdl.block> の中に記述されていたコードで生成されたものです。2 つ目の記事リストは、<#hoge /> タグによってブロック「hoge」を呼び出すことで生成されたものです。<sdl.block> と </sdl.block> タグをそれぞれ <sdl.function> と </sdl.function> タグに変更してみましょう。ブロックと同じく、関数の名前も name= 属性で定義します。
<sdl.function name="hoge">
<entries type="rchron" proj="*" max="5">
<loop.first><ul></loop.first>
<li>__entry.tractionid__ : __entry.title__</li>
<loop.last></ul></loop.last>
</entries>
</sdl.function>
<sdl.function>...</sdl.function> の中に書かれた内容は実行されないという特徴があります。つまり、関数は定義するだけでは実行されず、<#関数名 /
<sdl.function name="hoge">
<entries type="rchron" proj="*" max="5">
<loop.first><ul></loop.first>
<li>__entry.tractionid__ : __entry.title__</li>
<loop.last></ul></loop.last>
</entries>
</sdl.function>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>SDL Tutorial</title>
<html.css url="/html/css/sdllessons/styles.css" />
</head>
<body>
<h1>SDL 関数</h1>
<h2>記事リスト (1)</h2>
<#hoge />
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>SDL Tutorial</title>
<html.css url="/html/css/sdllessons/styles.css" />
</head>
<body>
<h1>SDL 関数</h1>
<h2>記事リスト (1)</h2>
<#hoge />
</body>
</html>
<sdl.function name="hoge">
<entries type="rchron" proj="*" max="5">
<loop.first><ul></loop.first>
<li>__entry.tractionid__ : __entry.title__</li>
<loop.last></ul></loop.last>
</entries>
</sdl.function>
<#関数名 /> や <sdl.include template="#関数名" /> で呼び出す前に置かれていても後ろに置かれていても、どちらでも動作します。<#hoge /> .<lib#hoge /> .<com.traction.sdl.example.foo#hoge /> .<com.traction.sdl.example.foo /> .<sdl.include template="#hoge" /> <sdl.include template="lib#hoge" /> <sdl.include template="com.traction.sdl.example.foo#hoge" /> <sdl.include template="com.traction.sdl.example.foo" />
<!--XXX include failed. template not found: '#関数名' XXX-->
<sdl.function name="関数名"> ... </sdl.function> タグを使う。<sdl.function name="関数名"> ... </sdl.function> の中に書かれた内容は、関数定義時には実行されない。<#関数名 /> または <sdl.include template="#関数名" /> タグを使う。lesson14.properties
image1.png
image2.png