TemplateSyntax - xpressengine/xe-core GitHub Wiki
XE ํ ํ๋ฆฟ์ PHP ๋ฌธ๋ฒ์ ๊ธฐ์ดํ๋ฉฐ, ๋ฌธ๋ฒ์ ๊ฐ์ํํ๊ณ HTML ํ๊ทธ์ ์ ์ด์ฐ๋ฌ์ง๋๋ก ๋ง๋ค์์ต๋๋ค.
XE ํ
ํ๋ฆฟ์ ํฌ๊ฒ ์ธ ๊ฐ์ง ํํ์
๋๋ค. ์ค๊ดํธ({}
), HTML ์ฃผ์(<!-- -->
) ๊ทธ๋ฆฌ๊ณ HTML ์์ฑ์ผ๋ก ์ง์ ํ ์ ์์ต๋๋ค.
์ค๊ดํธ๋ ๋ณ์์ ๊ฐ์ ์ถ๋ ฅํ๊ฑฐ๋ ํ ๋นํ ๋ ์ฌ์ฉํ๋ฉฐ, HTML ์ฃผ์ ํํ๋ if, foreach์ ๊ฐ์ ์กฐ๊ฑด๋ฌธ์ด๋ ๋ฐ๋ณต๋ฌธ์ผ๋ก ์ฌ์ฉ๋ฉ๋๋ค. ๋ํ, ์ ์ด๋ฌธ ๋ฑ์ HTML์ ์์ฑ์ด๋ ํ๊ทธ์ ํํ๋ก ์ฌ์ฉ๋๊ธฐ๋ ํฉ๋๋ค.
{$var}
{@ $is_logged = true}
<!--@if($is_logged)--> ... <!--@endif-->
<!--@foreach($arr as $val)--> ... <!--@endforeach-->
<div cond="$is_logged"> ... </div>
<load target="./css/style.css" />
HTML ์ฃผ์๊ณผ ๋์ผํ์ง๋ง ์นํ์ด์ง์๋ ์ถ๋ ฅํ๊ณ ์ถ์ง ์์ ๋ด์ฉ์ ๋ด์ ๋ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๊ฐ์ถ๊ณ ์ถ์ ์ฃผ์์ <!--// -->
์ด์ฒ๋ผ ์ฃผ์์ ์ฌ๋ ๊ตฌ๋ฌธ์ //
๋ฅผ ์ถ๊ฐํ๋ฉด ๋ฉ๋๋ค.
<!--// ๋ก๊ทธ์ธ ํผ ์์ -->
<form>
...
<!-- ๋ก๊ทธ์ธ ๋ฒํผ -->
<!--// ํฐ ๋ฒํผ์ผ๋ก ํ์ํ๋ ค๋ฉด 'large' class๋ฅผ ์ถ๊ฐํ๋ฉด ๋จ -->
<button class="btn-login">๋ก๊ทธ์ธ</button>
</form>
<!--// ๋ก๊ทธ์ธ ํผ ๋ -->
์ ํ
ํ๋ฆฟ์ ๋ค์๊ณผ ๊ฐ์ด <!--// -->
์ฝ๋๋ฅผ ์ ๊ฑฐ ํ ์ถ๋ ฅ๋ฉ๋๋ค.
<form>
...
<!-- ๋ก๊ทธ์ธ ๋ฒํผ -->
<button class="btn-login">๋ก๊ทธ์ธ</button>
</form>
{$๋ณ์์ด๋ฆ}
๊ณผ ๊ฐ์ ํํ๋ก ํ
ํ๋ฆฟ์ ์์ฑํ๋ฉด ๋ณ์๋ฅผ ํ๋ฉด์ ์ถ๋ ฅํ ์ ์์ต๋๋ค.
๋จ, ์ด๋ฆ์ด ์ธ๋์ค์ฝ์ด ๋ ๊ฐ(__)๋ ์ซ์, ๊ณต๋ฐฑ, ์ธ๋์ค์ฝ์ด ๋ฌธ์ ์ด์ธ์ ํน์ ๋ฌธ์๋ก ์์ํ๋ ๋ณ์๋ ์ฌ์ฉํ ์ ์์ต๋๋ค. ๋ณ์ ๋์ ํจ์๋ฅผ ์คํํ๊ณ ๋ฐํํ๋ ๊ฐ์ ์ถ๋ ฅํ ์๋ ์์ต๋๋ค.
// ์ฌ๋ฐ๋ฆ
{$varname}
{$_var2name}
{substr($varname, 0, 5)}
{$varname.'suffix'}
{className::$property}
{className::getProperty()}
// ์ฌ๋ฐ๋ฅด์ง ์์
{$123number}
{$__two_underscore}
{@ ... }
๋ฌธ๋ฒ์ ์ฌ์ฉํ๋ฉด ์ค๊ดํธ ์์ ๋ด์ฉ์ ์ถ๋ ฅํ์ง ์๊ณ , ๋ณ์์ ๊ฐ์ ํ ๋นํ ๋ ์ฌ์ฉํ ์ ์์ต๋๋ค. ๋ณ์์ ๊ฐ์ด๋ ํจ์์ ์คํ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ์ง ์๊ณ ์คํ๋ง ํ ๋ ์ฌ์ฉํฉ๋๋ค.
{@ $cms = 'xe'}
{@ $now = date()}
์๋ฐ์คํฌ๋ฆฝํธ ๋ฑ์์ ์ค๊ดํธ๋ฅผ ์ฌ์ฉํ ๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ง ์๋๋ก ํ๊ธฐ ์ํด ์ค๊ดํธ ๋ฌธ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ด ์ด์ค์ผ์ดํํ ์ ์์ต๋๋ค.
- ์ฌ๋ ์ค๊ดํธ
{
์ ๋ซ๋ ์ค๊ดํธ}
๋ฅผ ์๋ก ๋ค๋ฅธ ์ค์ ์ ๋ ฅํ๋ค. - ๋๋, ์ฌ๋ ์ค๊ดํธ
{
๋ค์ ๊ณต๋ฐฑ์ ์ ๋ ฅํ๋ค. ๋๋, ์ฃผ์๋ฌธ(/**/
)์ ์ฌ์ฉํ ์๋ ์์ต๋๋ค.
function () {
return true;
}
function () { return true; }
function () {/**/return true;}
JavaScript, CSS ํ์ผ์ ๋ถ๋ฌ๋ค์ด๊ฑฐ๋ ์ ๊ฑฐํ๋ ค๋ฉด load
๋๋ unload
๋ฌธ๋ฒ์ ์ฌ์ฉํ ์ ์๊ณ , ๋ค๋ฅธ ํ์ผ์ ๋ด์ฉ์ ์ถ๋ ฅํ๋ ค๋ฉด include
๋ฌธ๋ฒ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
์ด ๋ฌธ๋ฒ์ ์ ํจํ XML ๋
ธ๋์ฌ์ผ ํ๊ณ ์๊ธฐ ์์ ์ ๋ฐ๋ก ๋ซ๋ ํ๊ทธ(self-closing tag)์ด๋ฏ๋ก >
๊ธฐํธ ์์ ๋ฐ๋์ ์ฌ๋์(/)๋ฅผ ํฌํจํด์ผ ํฉ๋๋ค.
JavaScript, CSS ๋ฑ์ ์ธ๋ถ ํ์ผ์ ํ์ด์ง์ ๋ก๋ํ๋ ค๋ฉด load
ํ๊ทธ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
target
์์ฑ์ผ๋ก ์ง์ ํ ํ์ผ์ ํ์ฅ์์ ๋ฐ๋ผ ๋์์ด ๋ฌ๋ผ์ง๋ฏ๋ก ์๋ฐ์คํฌ๋ฆฝํธ ํ์ผ์ ๋ฐ๋์ .js
๋ฅผ, CSS ํ์ผ์ ๋ฐ๋์ .css
๋ฅผ ํ์ฅ์๋ก ์ฌ์ฉํด์ผ ํฉ๋๋ค.
target
์ ์ง์ ํ๋ ํ์ผ์ ํ
ํ๋ฆฟ ํ์ผ์ ์์น๋ฅผ ๊ธฐ์ค์ผ๋ก ์๋ ๊ฒฝ๋ก๋ก ์ง์ ํ ์ ์์ต๋๋ค.
<load target="path/to/style.css" />
<load target="path/to/script.js" />
load
ํ๊ทธ์ ์ฌ์ฉํ ์ ์๋ ์์ฑ์ ๋ค์๊ณผ ๊ฐ๋ค.
- target : ํ์ผ์ ๊ฒฝ๋ก. ํ์ฌ ํ ํ๋ฆฟ ํ์ผ์ ๊ฒฝ๋ก๋ฅผ ๊ธฐ์ค์ผ๋ก ํจ
- media : (CSS ์ ์ฉ) CSS์
media
์์ฑ. ๊ธฐ๋ณธ๊ฐ์"all"
์ด๋ค. - type : (JS ์ ์ฉ) ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ์ถ๋ ฅํ ์์น๋ฅผ ์ ํ๋ค.
head
(๊ธฐ๋ณธ๊ฐ) ๋๋body
๋ฅผ ์ฌ์ฉํ ์ ์๋ค.body
๋ฅผ ์ ๋ ฅํ๋ฉด ๋ซ๋</body>
ํ๊ทธ ๋ฐ๋ก ์์ ๋ฑ๋ก๋ ์์๋๋ก ์ถ๋ ฅ๋๋ค. - targetie : IE์ ์กฐ๊ฑด๋ถ ์ฃผ์์ ์ฌ์ฉํ ๋ ์ค์ ํ๋ค. ์กฐ๊ฑด๋ถ ์ฃผ์์ ์
๋ ฅํ๋ ๋ฌธ์์ด๊ณผ ๊ฐ์ด
IE 6
,gt IE 6
๋ฑ์ผ๋ก ๊ฐ์ ์ ๋ ฅํ๋ค. - index : ์ฐ์ ์์๋ฅผ ์ค์ ํ๋ค. ํน๋ณํ ๋ฌธ์ ๊ฐ ์๋ค๋ฉด ์ฌ์ฉํ์ง ์๋ ํธ์ด ์ข๋ค.
load
ํ๊ทธ๋ ์ธ์ด ํ์ผ์ ๋ถ๋ฌ์ฌ ๋๋ ์ฌ์ฉํ ์ ์๋ค. target
์์ฑ์ lang.xml
ํ์ผ์ ๊ฒฝ๋ก๋ฅผ ์
๋ ฅํ๋ฉด ํด๋นํ๋ ์ธ์ด๋ฅผ ์ฝ์ด๋ค์ธ๋ค.
<load target="../lang/lang.xml" />
PHP์์ ์ฌ์ฉํ๋ include
๋ฌธ๊ณผ ๋น์ทํ ์ญํ ์ ํ๋ฉฐ. ์ค์ ํ ํ
ํ๋ฆฟ ํ์ผ์ ์ฝ์ด๋ค์ฌ ํด์ํ๊ณ ํ๋ฉด์ ์ถ๋ ฅํฉ๋๋ค.
include
ํ๊ทธ๋ฅผ ์ฌ์ฉํ๊ณ , target
์์ฑ์ ์ฝ์ด๋ค์ธ ํ์ผ์ ์
๋ ฅํ๋ฉด ๋๋ค. ์ฝ์ด๋ค์ผ ํ์ผ์ ๊ฒฝ๋ก๋ ํ์ฌ ํ
ํ๋ฆฟ ํ์ผ์ ๊ธฐ์ค์ผ๋ก ํ๋ค.
<include target="header.html" />
unload
ํ๊ทธ๋ load
๋ก ์ฝ์ด๋ค์ธ ํ์ผ์ ์ ๊ฑฐํ ๋ ์ฌ์ฉํ๋ค. load
๋ฅผ ์ฌ์ฉํ ๋์ ๊ฐ์ ์์ฑ์ ์
๋ ฅํ๋ฉด ์ฝ์ด๋ค์ธ ํ์ผ์ ์ ๊ฑฐํ ์ ์๋ค.
<unload target="path/to/style.css" media="all" />
unload
ํ๊ทธ์ ์ฌ์ฉํ ์ ์๋ ์์ฑ์ ๋ค์๊ณผ ๊ฐ๋ค.
- target : ์ฝ์ด๋ค์ธ ํ์ผ์ ๊ฒฝ๋ก
- media : (CSS ์ ์ฉ) CSS์
media
์์ฑ - type : (JS ์ ์ฉ) ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ์ถ๋ ฅํ ์์น
- targetie : IE์ ์กฐ๊ฑด๋ถ ์ฃผ์
HTML ์์์ ํจ๊ป ์ฌ์ฉํ๋ ํํ์ ๋ฌธ๋ฒ์ด๋ค. ๋ธ๋ญ ๋ฌธ๋ฒ๊ณผ ๋ฌ๋ฆฌ ๋ณ๋์ ์์/๋์ ๋ณ๋๋ก ์ง์ ํ์ง ์์ผ๋ฉฐ, ๋ฌธ๋ฒ์ด ์ ์ฉ๋ DOM์ ๋์์ผ๋ก ํ๋ค. ์๋ฅผ ๋ค์ด, ๋ค์์ ๊ฐ๋จํ ์กฐ๊ฑด๋ฌธ์ ํ ์์ด๋ค.
<img src="img.jpg" alt="Sample image" cond="$cond" />
cond
๋ฌธ์ ์ ํจ ๋ฒ์๋ ๋ฌธ์ฅ์ด ์ ์ฉ๋ DOM ์์ <img>
์ด๋ค. ๋ฐ๋ผ์ ์ด ํ
ํ๋ฆฟ์ ๋ค์๊ณผ ๊ฐ์ PHP ์ฝ๋๋ก ๋ณํ๋๋ค.
<?php if($cond){ ?><img src="img.jpg" alt="Sample image" /><?php } ?>
์ด ๋ฐ์ ์์ฑ๊ณผ ํจ๊ป ์ฌ์ฉํ๋ ์์ฑ ์กฐ๊ฑด๋ฌธ๋ ์๋ค.
๋ค๋ฅธ ๋ฌธ๋ฒ์ด DOM ์์์ ์์ฉํ๋ ๋ฐ๋ฉด, ์์ฑ ์กฐ๊ฑด๋ฌธ์ ํน์ ์์ฑ์๋ง ์์ฉํ๋ค.
ํน์ ์์ฑ ๋ค์ ํ์ดํ ๋ฌธ์(|)์ cond="$cond"
๋ฌธ๋ฒ์ ์ฌ์ฉํ๋ฉด ์กฐ๊ฑด์ ๋ง์กฑํ ๋๋ง ์์ฑ์ ์ถ๋ ฅํ๋ค.
๋ค์์ $isActive
์ ๊ฐ์ด true์ผ ๋๋ง class="active"
์์ฑ์ ์ถ๋ ฅํ๋ ํ
ํ๋ฆฟ ์์ ์ด๋ค.
<a href="http://localhost" class="active"|cond="$isActive">Go</a>
์ ํ ํ๋ฆฟ์ ์คํํ๋ฉด $active์ ๊ฒฐ๊ณผ์ ๋ฐ๋ผ ์๋ก ๋ค๋ฅธ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๋ค.
// $isActive = true ์ผ ๋
<a href="http://localhost" class="active">Go</a>
// $isActive = false ์ผ ๋
<a href="http://localhost">Go</a>
ํจ์๋ฅผ ํธ์ถํ ์๋ ์์ต๋๋ค
<a href="http://localhost" class="active"|cond="$obj->isActivated()">Go</a>
ํน์ ์กฐ๊ฑด์ ๋ง์กฑํ ๋๋ง DOM ์์๋ฅผ ์ถ๋ ฅํ๋๋ก ํ๋ค. ์กฐ๊ฑด๋ฌธ์ ์ ์ฉํ DOM ๋
ธ๋์ cond
์์ฑ์ ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ๋ฉด ๋๋ค.
<img src="img.jpg" alt="Sample image" cond="$cond" />
์ด ํ ํ๋ฆฟ์ ๋ค์๊ณผ ๊ฐ์ PHP ๋ฌธ๋ฒ์ผ๋ก ๋ณ๊ฒฝ๋๋ค.
<?php if($cond){ ?><img src="img.jpg" alt="Sample image" /><?php } ?>
์์ ์์๋ฅผ ํฌํจํ DOM์๋ ์ ์ฉํ ์ ์๋ค.
<div class="buttons" cond="$showButtons">
<button type="button">Save</button>
<button type="button">Reset</button>
</div>
์ด ํ ํ๋ฆฟ์ ๋ค์๊ณผ ๊ฐ์ PHP ๋ฌธ๋ฒ์ผ๋ก ๋ณ๊ฒฝ๋๋ค.
<?php if($showButtons){ ?>
<div class="buttons">
<button type="button">Save</button>
<button type="button">Reset</button>
</div>
<?php } ?>
ํน์ DOM ์์๋ฅผ ์ฃผ์ด์ง ์กฐ๊ฑด์ ๋ฐ๋ผ ๋ฐ๋ณต ์ถ๋ ฅํ๋ค. ๋ฐ๋ณต๋ฌธ์ ์ ์ฉํ DOM ๋
ธ๋์ loop
์์ฑ์ ์ฌ์ฉํ๋ฉด ๋๋ค.
๋ค์์ $arr
๋ฐฐ์ด์ ํญ๋ชฉ ๊ฐฏ์๋งํผ ๋ฐ๋ณตํด์ ์ถ๋ ฅํ๋ ํ
ํ๋ฆฟ ์์ ์ด๋ค.
// ํ
ํ๋ฆฟ
<ul>
<li loop="$arr=>$val">Item : {$val}</li>
</ul>
// PHP
<ul>
<?php foreach($arr as $val){ ?>
<li>Item : <?php echo $val ?></li>
<?php } ?>
</ul>
๋ฐฐ์ด์ ์ธ๋ฑ์ค๋ ์ฐ๊ด ๋ฐฐ์ด์ ํค ์ด๋ฆ์ ์ฌ์ฉํ๋ ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด ํ ํ๋ฆฟ์ ์์ฑํ ์ ์๋ค.
// ํ
ํ๋ฆฟ
<ul>
<li loop="$arr=>$key,$val">Item {$key} : {$val}</li>
</ul>
// PHP
<ul>
<?php foreach($arr as $key=>$val){ ?>
<li>Item <?php echo $key ?>: <?php echo $val ?></li>
<?php } ?>
</ul>
์ผ์ ํ์๋ฅผ ๋ฐ๋ณตํ ๋ ์ฌ์ฉํ๋ for
๋ฌธ๋ฒ๋ ์ฌ์ฉํ ์ ์๋ค.
// ํ
ํ๋ฆฟ
<ul>
<li loop="$i=0; $i < count($arr); $i++">Item : {$arr[$i]}</li>
</ul>
// PHP
<ul>
<?php for($i=0; $i < count($arr); $i++){ ?>
<li>Item : <?php echo $i ?></li>
<?php } ?>
</ul>
์๋ฅผ ๋ค์ด $arr
์ด 1,2,3,4,5
๋ค์ฏ ๊ฐ์ ์ซ์๋ฅผ ์ ์ฅํ ๋ฐฐ์ด์ด๋ผ๋ฉด ์ด ํ
ํ๋ฆฟ์ ๋ค์๊ณผ ๊ฐ์ด ์ถ๋ ฅ๋๋ค.
<ul>
<li>Item : 1</li>
<li>Item : 2</li>
<li>Item : 3</li>
<li>Item : 4</li>
<li>Item : 5</li>
</ul>
ํน์ ์กฐ๊ฑด์ ๋ง์กฑํ๋ ๋์ ๊ณ์ ๋ฐ๋ณตํ๋ while
๋ฌธ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ๋ค. while
๋ฌธ๋ฒ์ ํํ์์ ๋ฐ๋์ ๋ณ์์ ๊ฐ์ ํ ๋นํ๋ ํํ์ฌ์ผ ํ๋ค.
// ํ
ํ๋ฆฟ
<ul>
<li loop="$item=get_item()">Item : {$item}</li>
</ul>
// PHP
<ul>
<?php while($item=get_item()){ ?>
<li>Item : <?php echo $item ?></li>
<?php } ?>
</ul>
์ฌ๋ฌ ๊ฐ์ DOM์ ํ๊บผ๋ฒ์ ๋ค๋ฃจ์ด์ผ ํ๋ ๋ฑ ํ ๊ฐ์ DOM๋ง ๋ค๋ค์ ์ํ๋ ๊ฒฐ๊ณผ๋ฅผ ์ป๊ธฐ ์ด๋ ค์ธ ๋๋ ๊ฐ์ ๋
ธ๋ <block>
์ ์ฌ์ฉํ ์ ์๋ค.
๊ฐ์ ๋
ธ๋ <block>
์ ์ค์ ๋ก ํ๋ฉด์ ์ถ๋ ฅ๋์ง๋ ์์ง๋ง cond
๋ loop
๋ฅผ ์์ฑ์ผ๋ก ์ฌ์ฉํ ์ ์๋ค.
๋ค์ ํ
ํ๋ฆฟ ๊ตฌ๋ฌธ์ ๋ณด์.
<block cond="$cond">
<a href="link1.html">Link1</a>
<a href="link2.html">Link2</a>
</block>
์ด ์ฝ๋๋ฅผ PHP ์ฝ๋๋ก ๋ณํํ๋ฉด ๋ค์๊ณผ ๊ฐ์ ํํ๊ฐ ๋๋ค.
<?php if($cond){ ?>
<a href="link1.html">Link1</a>
<a href="link2.html">Link2</a>
<?php } ?>
๊ฐ์ ๋ ธ๋๋ ํ ํ๋ฆฟ ํ์ผ ์์ ์๋ ๋ค๋ฅธ HTML ์์์ ๋๋ฑํ๊ฒ ํ๋์ ์์ ํ ๋ ธ๋๋ก ์ทจ๊ธ๋์ด์ผ ํ๋ค. ๋ค์ ๋งํด ๋ค์๊ณผ ๊ฐ์ด ๋ ธ๋๋ฅผ ๊ธฐ์ ํ ๋ ๊ฐ์ ๋ ธ๋๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
// ์๋ชป๋ ์ฌ์ฉ๋ฒ
<a href="link.html" <block cond="$style">style="{$style}"</block> class="link">Link</a>
๋ธ๋ญ ๋ฌธ๋ฒ์ @
๋ก ์์ํ๋ HTML ์ฃผ์ ํ์์ผ๋ก ์์ฑํ๋ค.
์กฐ๊ฑด๋ฌธ์๋ if
, else
, elseif
๊ฐ ์๊ณ if
๋ก ์์ํ ๊ตฌ๋ฌธ์ ๋ซ์ ๋๋ endif
๋ฅผ ์ฌ์ฉํ๋ค.
์กฐ๊ฑด์ ๋น๊ตํ์ฌ ์กฐ๊ฑด์ ๋ง์ผ๋ฉด ๋ธ๋ญ ์์ ํ
ํ๋ฆฟ์ ์ถ๋ ฅํ๋ค. if
๋ก ์์ํ๊ณ endif
๋ก ๋ธ๋ญ์ ๋ง์น๋ฉฐ, elseif
์ else
๋ฑ์ ๋ธ๋ญ ์์์ ์ฌ์ฉํ ์ ์๋ค(elseif
์ ๊ณต๋ฐฑ์ด ์์์ ์ฃผ์).
๋ค์์ ๊ฐ์ฅ ๊ฐ๋จํ if
๋ฌธ ์์ ์ด๋ค.
<!--@if($var)-->Is this printed?<!--@endif-->
๋ค์ ์์ ์ฒ๋ผ else
๋๋ elseif
๋ฌธ์ ์ถ๊ฐํด ๋ค์ํ ์กฐ๊ฑด์ ๋น๊ตํ ์๋ ์๋ค.
<!--@if($var)-->
I am the first!
<!--@elseif($another_var)-->
Second. Not bad.
<!--@else-->
Oops. I am the last.
<!--@endif-->
๋ฐฐ์ด์ด๋ ๊ฐ์ฒด ๋ฑ ๊ฐ์ ๋์ดํ ์ ์๋(enumerable) ๊ฐ์ฒด์ ๋ํด ๋ฐ๋ณต๋ฌธ์ ์คํํ๋ค. for
, foreach
, while
๋ก ์์ํ๊ณ ๊ฐ๊ฐ endfor
, endforeach
, endwhile
๋ก ๋ธ๋ญ์ ๋ง์น๋ค.
for
๋ก ์์ํ๊ณ endfor
๋ก ๋ง์น๋ ๋ฐ๋ณต๋ฌธ์ด๋ค. ๋ฐ๋ณต ํ์๊ฐ ์ ํด์ง ๊ฒฝ์ฐ์ ์ ์ฉํ๋ค.
<!--@for($i = 0; $i < 10; $i++)-->
<span>Number : {$i}</span>
<!--@endfor-->
foreach
๋ก ์์ํ๊ณ endforeach
๋ก ๋ง์น๋ ๋ฐ๋ณต๋ฌธ์ด๋ค. ๋ฐฐ์ด์ด๋ ๊ฐ์ฒด๋ฅผ ์ฒ์๋ถํฐ ๋๊น์ง ๋ฐ๋ณตํ ๋ ์ ์ฉํ๋ค.
<!--@foreach($arr as $key=>$name)-->
<span>Item {$key} : {$name}</span>
<!--@endforeach-->
while
๋ก ์์ํ๊ณ endwhile
๋ก ๋ง์น๋ ๋ฐ๋ณต๋ฌธ์ด๋ค. ๋ฐ๋ณต ํ์๋ฅผ ์ ์ ์์ ๋ ์ ์ฉํ๋ค.
<!--@while($item=get_item())-->
<span>Item : {$item}</span>
<!--@endwhile-->