Template syntax v1 (legacy)
Template v1 is the syntax carried over from the XE days. Most existing resources are built with it, so it's documented here for maintenance and reference. Build new resources with Template syntax v2.
Output
{$variable}
{$object->method()}
{$array[$key]}It doesn't work if you put a space right after the opening brace or break the line in the middle ({ $name } is not output).
Filters are the same as in v2.
{$var|lower|escape}
{$timestamp|date:'Y-m-d H:i'}
{$number|number_format}Conditions and loops: HTML comment style
<!--@if($condition)-->
<div>참</div>
<!--@else-->
<div>거짓</div>
<!--@endif-->
<!--@foreach($list as $key => $item)-->
<li>{$item->title}</li>
<!--@endforeach--><!--@for(...)--> and <!--@while(...)--> work the same way.
Attribute style: cond / loop
This is v1's most distinctive syntax. Conditions and loops are attached to tags as attributes.
<div cond="$is_logged">로그인 상태에서만 보임</div>
<li loop="$list => $key, $item">{$item->title}</li>You can also make an attribute value itself conditional.
<option value="foo" selected="selected"|cond="$val === 'foo'">FOO</option>
<input type="checkbox" checked="checked"|cond="$item->checked" />To group without a tag, use <block> (this syntax isn't supported in v2).
<block cond="$show">
여러 요소를 한 번에
</block>PHP code
{@ $foo = 'bar'}
{@
$foo = 'bar';
if ($condition):
$enabled = true;
endif;
}Caution: {@ ... } matches only up to the first }. If you use a brace block (if (...) { ... }) inside the code, it gets cut off. Use the if (...): / endif; style.
Includes and loading resources
<include target="_header.html" />
<include target="^/common/tpl/refresh.html" /> <!--// ^ 는 사이트 루트 -->
<include target="_promo" cond="$show_promo" />
<load target="css/skin.css" />
<load target="css/skin.css" media="print" index="20" />
<load target="js/skin.js" type="body" />
<unload target="js/old.js" /><!--#include(...)-->, <!--%import(...)-->, and <!--%load_js_plugin(...)--> are older notations; don't use them in new code.
Comments
<!-- 출력에 남는 일반 HTML 주석 -->
<!--// 출력에서 제거되는 템플릿 주석 -->Automatic features (shared by v1 and v2)
- Automatic resource path conversion: if you use a relative path such as
<img src="img/icon.png" />, it's output as an absolute path based on the skin path. - Automatic form injection:
<form method="post">automatically gets the required hidden fields such as mid, act, and CSRF. Addingruleset="name"also links validation rules. To turn off automatic injection, userx-autoform="false"; to leave out only error_return_url, useno-error-return-url="true". - Automatic escaping: if you declare
<config autoescape="on" />at the very top of the file, escaping is applied to all{$var}output. Old files without this declaration aren't escaped, so be careful when outputting user input.
Relationship with v2
- v1 syntax keeps working, and even inside v2 files some
condattributes (conditions on<include>),{$var}output, and{@ }code are compatible. - Conversely, v2 directives such as
@ifdon't work in v1 files. Whether the first line declares@version(2)is what decides. - When fixing an existing v1 skin, keep fixing it in v1, and we recommend switching to v2 when you rebuild it substantially.