IV. WORKING WITH DESIGNER
18.  ÁÖ¼®
¡Ø  ²¿¸®¸»Çü ÁÖ¼®
¸í·É¾î ÀÇ¹Ì »ç¿ë¹ý
// º¯È¯½Ã ű׳» '//' ÀÌÇϹ®ÀÚ »èÁ¦ { any_template_code // any_string }
ÅÛÇø´Äڵ尡 À¯È¿ÇÏÁö ¾Ê°Å³ª À̽ºÄÉÀÌÇÁµÇ¾úÀ» ¶§´Â »èÁ¦µÇÁö ¾Ê½À´Ï´Ù.
²¿¸®¸»Çü ÁÖ¼® ¿¹Á¦ 
index.tpl
<table>
<!--{@ list // loop starts!! }-->
<tr>
    <td>{start - .index_ // list number }</td>
    <td>{.title}</td>
</tr>
<!--{/// list ends!! }-->
</table>
¡Ø  ºí·°Çü ÁÖ¼®
¸í·É¾î ÀÇ¹Ì »ç¿ë¹ý
* º¯È¯ÆÄÀÏ¿¡¼­ »èÁ¦µÊ {* any_string *}
ºí·°Çü ÁÖ¼® ¿¹Á¦ 
index.tpl
<!--{* Template {comments} are {removed} in compiled file *}-->
<table>
<tr>
    <td width="50px">
        <!--{ template * expression / overflows + width50px }-->{*no*}
    </td>
    <td width="250px">
        { width250px & is | enough }
    </td>
</tr>
</table>
{* *} , <!--{* *} , {* *}--> , <!--{* *}--> ¸ðµÎ À¯È¿ÇÑ ÅÛÇø´ ÁÖ¼®À̸ç, ÁÖ¼®ÀÇ À̽ºÄÉÀÌÇÁ¹æ¹ýÀº ·¹ÆÛ·±½º¿¡¼­ ÁÖ¼®¸í·É¾î¸¦ Âü°íÇϽñ⠹ٶø´Ï´Ù.
¶ÇÇÑ ÅÛÇø´ÀÇ Ã¹¹øÂ° ºí·°Çü ÁÖ¼®Àº ¾Æ·¡¿¡ ¼³¸íµÉ ¸ÅÅ©·Î, ÇÊÅÍ µîÀ» Á¤ÀÇÇÒ ¼ö ÀÖ´Â ¿µ¿ªÀÔ´Ï´Ù.
19.  ¸ÅÅ©·Î
¸í·É¾î ÀÇ¹Ì »ç¿ë¹ý
#define ¹®ÀÚ¿­ ġȯ Á¤ÀÇ #define search_string replace_string
ÅÛÇø´ º¯È¯±â°¡ ÅÛÇø´ Äڵ带 ÇØ¼®Çϱâ Àü¿¡, ¸ÅÅ©·ÎÁ¤ÀÇ¿¡ µû¶ó ¹®ÀÚ¿­µéÀ» ġȯÇÕ´Ï´Ù. ¸ÅÅ©·Î´Â ÅÛÇø´ ÆÄÀÏÀÇ °¡Àå óÀ½ ºí·°Çü ÁÖ¼®¿¡¼­¸¸ Á¤ÀÇÇÒ ¼ö ÀÖ½À´Ï´Ù.
index.tpl
<!--{*
#define  div  span
#define  Greeting  "Hello! Julia"
*}-->

<div>Greeting</div>
>> output
<span>Hello! Julia</span>
ãÀ» ¹®ÀÚ¿­, ¹Ù²Ü ¹®ÀÚ¿­ ¸ðµÎ µû¿ÈÇ¥·Î °¨½Ò ¼ö ÀÖ°í, °ø¹é(°ø¹é, ÅÇ, ÁٹٲÞ)ÀÌ Æ÷Ç﵃ ¶§´Â ¹Ýµå½Ã µû¿Èǥó¸®ÇÕ´Ï´Ù.
¾Æ·¡ÀÇ µÎ ÅÛÇø´ÆÄÀÏÀº °°Àº º¯È¯ÆÄÀÏ·Î º¯È¯µË´Ï´Ù.
index.tpl
<!--{@ page}-->
    <!--{? page.key_ == current }-->
        [ {page.key_} ]
    <!--{:}-->
        <a href='{page.value_}'>[ {page.key_} ]</a>
    <!--{/}-->
<!--{:}-->
    -- no page --
<!--{/}-->
index.tpl
<!--{*
#define  <!--current_page--\>  {@page}{?page.key_==current}
#define  <!--other_page--\>  {:}
#define  <!--no_page--\>  {/}{:}
#define  <!--page_end--\>  {/}
*}-->

<!--current_page-->
    [ {page.key_} ]
<!--other_page-->
    <a href='{page.value_}'>[ {page.key_} ]</a>
<!--no_page-->
    -- no page --
<!--page_end-->
ãÀ» ¹®ÀÚ¿­, ¹Ù²Ü ¹®ÀÚ¿­ ³»¿¡ ´ÙÀ½ÀÇ À̽ºÄÉÀÌÇÁ ¹®ÀÚ¿­ÀÌ À¯È¿ÇÕ´Ï´Ù.
escape sequences
\\    \t    \n    \"    \'    \> (\g)
\n Àº ¿¡µðÅͰ¡ »ç¿ëÇÏ´Â Áٹٲ޹®ÀÚ¿¡ ÇØ´çÇϹǷΠ\r À» °í·ÁÇÏÁö ¾Ê¾Æµµ µË´Ï´Ù. À§ÁöÀ¨¿¡µðÅÍ·Î ÀÛ¾÷½Ã ¹®ÀÚ¿­¿¡ "-->" ÀÌ Æ÷ÇÔµÇ¸é ¾ÈµÇ¹Ç·Î ÀÌ ¶§ "--\>" ¶Ç´Â "--\g" ·Î »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.
20.  ÇÁ¸®ÇÊÅÍ
ÅÛÇø´ º¯È¯±â´Â "ÅÛÇø´ÁÖ¼®»èÁ¦ -> ¸ÅÅ©·Îó¸® -> ÇÁ¸®ÇÊÅ͸µ -> ÅÛÇø´º¯È¯ -> Æ÷½ºÆ®ÇÊÅ͸µ
-> º¯È¯ÆÄÀÏÀúÀå" ÀÇ ¼ø¼­·Î ÀÛµ¿ÇÕ´Ï´Ù.
¡Ø  ¾Æ·¡¿Í °°Àº Çü½ÄÀÇ ÇÔ¼ö¸¦ "prefilter.ÇÔ¼öÀ̸§.php" ÀÇ ÆÄÀϸíÀ¸·Î ¹èÆ÷µÈ Ç÷¯±×ÀÎ µð·ºÅ丮 ³»¿¡ ÀúÀåÇϸé ÇÊÅÍÇÔ¼ö·Î »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.
prefilter.arrangeSpace.php
<?php
function arrangeSpace($source, $tpl) {
    ...
    return $source;
}
?>
ÇÁ¸®ÇÊÅÍÇÔ¼ö´Â ÅÛÇø´ÁÖ¼®»èÁ¦ ¹× ¸ÅÅ©·Îó¸®µÈ ÅÛÇø´¼Ò½º¸¦ ù¹øÂ° ÀÎÀÚ·Î ¹Þ¾Æ, °¡°øÇؼ­ ¸®ÅÏÇÕ´Ï´Ù.
¡Ø  ÇÁ¸®ÇÊÅ͸¦ »ç¿ëÇÏ·Á¸é  $prefilter ¼Ó¼º¿¡ »ç¿ëÇÒ ÇÊÅÍÇÔ¼öÀ̸§À» ÁöÁ¤ÇÕ´Ï´Ù.
$tpl->prefilter = 'arrangeSpace';
¿©·¯ °¡Áö ÇÊÅ͸µÀÌ ÇÊ¿äÇÑ °æ¿ì, ¸Þ¼­µå¸íÀ» ÆÄÀÌÇÁ "|" ·Î ¿¬°áÇÏ¸é ¼ø¼­´ë·Î 󸮵˴ϴÙ.
$tpl->prefilter = 'adjustPath | parseMySyntax | myFilter';
ÇÊÅÍ ¸Þ¼­µå¿¡ Ãß°¡ÀûÀÎ ÀÎÀÚ°ªÀ» Àü´ÞÇÏ·Á¸é "&" ·Î ±¸ºÐÇØ¼­ ÁöÁ¤ÇÕ´Ï´Ù.
index.php
$tpl->prefilter = "myFilter & value1 & value2 | adjustPath";
prefilter.myFilter.php
<?php
function myFilter($source, $tpl, $arg1, $arg2) {
    ...
    return $source;
}
?>
ÀÎÀÚ°ª¿¡ & ¶Ç´Â | °¡ ÇÊ¿äÇÏ´Ù¸é  \&, \| ·Î À̽ºÄÉÀÌÇÁÇØ¼­ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.
¡Ø  Ã¹¹øÂ° ÅÛÇø´ÁÖ¼® ³»¿¡¼­ #prefilter ¸í·É¾î·Î Ãß°¡ÀûÀÎ ÇÊÅͼ³Á¤À» ÇÒ ¼ö ÀÖ½À´Ï´Ù.
<!--{*
#prefilter "parseMySyntax & bbslist | someSpecialFilter"
#define ...
*}-->
$prefilter #prefilter >> result sequence
"f1 | f2" "f3 | f4" "f3 | f4"
"f1 | f2" "| f3 | f4" "f1 | f2 | f3 | f4"
"f1 | f2" "f3 | f4 |" "f3 | f4 | f1 | f2"
"f1 | f2" "" ""
21.  »ó´ë°æ·Î ÀÚµ¿º¸Á¤(ÇÁ¸®ÇÊÅÍ)
ÇÊÅ͸í ÀǹÌ
adjustPath ÅÛÇø´ÆÄÀϳ» »ó´ë°æ·Î¸¦ Àý´ë°æ·Î·Î º¯È¯
$tpl->prefilter = "adjustPath & css,js,jpg,jpeg,png,gif,swf";
ÁöÁ¤µÈ È®ÀåÀÚ¸¦ °¡Áø »ó´ë°æ·Î¸¦ º¯È¯Çϸç, »ó´ë°æ·Î´Â ÅÛÇø´ÆÄÀÏÀÇ À§Ä¡¸¦ ±âÁØÀ¸·Î ÇϹǷÎ, ÅÛÇø´ÆÄÀÏÀ» ºê¶ó¿ìÀú³ª À§ÁöÀ¨¿¡µðÅÍ·Î ¿­¾úÀ» ¶§µµ À̹ÌÁö, ½ºÅ¸ÀÏ½ÃÆ® µîÀÌ Àû¿ëµË´Ï´Ù.
ÀÎÀÚ¸¦ ÁöÁ¤ÇÏÁö ¾ÊÀ¸¸é ÇÊÅÍÇÔ¼ö³»ÀÇ ±âº»°ªÀ» »ç¿ëÇÕ´Ï´Ù.
¿¹Á¦ 
directory
/
project
www (web root)
_global (template directory)
_img
logo.gif
intro
img
back.gif
intro.tpl
intro
index.php
include
compiles (compile directory)
Template_.class.php
/project/www/intro/index.php
<?php
include '/project/include/Template_.class.php';
$tpl= new Template_;
$tpl->template_dir= '/project/www/_global';
$tpl->compile_dir= '/project/include/compiles';
$tpl->prefilter= 'adjustPath';

$tpl->define('index', 'intro/intro.tpl');
$tpl->print_('index');
?>
/project/www/_global/intro/intro.tpl
<img src="../_img/logo.gif">
<div style="background-image:url(img/back.gif)">
    welcome!
    '../_img/test.gif'
    \"../_img/test.gif\"
    \'../_img/test.gif\'

    src=../_img/test.gif     ....not quoted
    "\../_img/test.gif"      ....escaped
</div>
>>output
<img src="/_global/_img/logo.gif">
<div style="background-image:url(/_global/intro/img/back.gif)">
    welcome!
    '/_global/_img/test.gif'
    \"/_global/_img/test.gif\"
    \'/_global/_img/test.gif\'

    src=../_img/test.gif     ....not quoted
    "../_img/test.gif"      ....escaped
</div>
»ó´ë°æ·Î ¹®ÀÚ¿­ÀÌ Å« µû¿ÈÇ¥, ÀÛÀº µû¿ÈÇ¥, ¶Ç´Â url() ·Î ¹­¿©ÀÖ´Â °æ¿ì¿¡¸¸ º¯È¯µÇ¸ç, »ó´ë°æ·Î¾Õ¿¡ ¿ª½½·¡½¬ '\' ¸¦ ºÙ¿©¼­ À̽ºÄÉÀÌÇÁÇÒ ¼ö ÀÖ½À´Ï´Ù.
adjustPath ÇÊÅ͸¦ »ç¿ëÇÏ¿© À̹ÌÁö ¼­¹ö¸¦ ºÐ¸®Çϰųª À¥¼­¹öÀÇ ¸®´ÙÀÌ·º¼Ç°ú ¿¬µ¿ÇÏ´Â ¿ëµµ·Î »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. ·¹ÆÛ·±½º¸¦ Âü°íÇϽñ⠹ٶø´Ï´Ù.
22.  ÅÛÇø´ÆÄÀÏ ºÐÇÒ
ÅÛÇø´ ºÐÇÒ ±â´ÉÀ» »ç¿ëÇÔÀ¸·Î½á ¿©·¯ °³ÀÇ ÅÛÇø´À» ÇÑ ÆÄÀÏ¿¡ ÀÛ¼ºÇÒ ¼ö ÀÖ½À´Ï´Ù.
´Ù¸¥ ÆäÀÌÁö¿¡¼­ »ç¿ëÇÏ´Â ÅÛÇø´µéÀÌ °ü·ÃµÈ ³»¿ëÀ̰ųª, ÀÛ¼ºÇÑ ÅÛÇø´ÀÇ ÀϺθ¸ ´Ù¸¥ ÆäÀÌÁö¿¡¼­ ¹Ýº¹ »ç¿ëÇϰųª, ¸ðµÎ ÇÑ ÆäÀÌÁö¿¡¼­ Ãâ·ÂµÇÁö¸¸ ½Ã°£Â÷ Ãâ·ÂÀ» ÇϰíÀÚ ÇÒ ¶§ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.
¸í·É¾î ÀÇ¹Ì »ç¿ë¹ý
+ Ãß°¡ÀûÀÎ º¯È¯ÆÄÀÏ »ý¼º {+ division_id }
¾Æ·¡ÀÇ ÅÛÇø´ÆÄÀÏÀº ¼¼ °³ÀÇ º¯È¯ÆÄÀÏÀ» ¸¸µé°Ô µË´Ï´Ù.
layout.tpl
<!--{+ head}-->
<html>
<body>
<div>Welcome!</div>
<!--{+ body}-->
<table>
<tr><td>menu</td><td>content</td></tr>
</table>
</body>
</html>
> layout.tpl.php
<html>
<body>
<div>Welcome!</div>
<table>
<tr><td>menu</td><td>content</td></tr>
</table>
</body>
</html>
> layout.tpl.head.php
<html>
<body>
<div>Welcome!</div>
> layout.tpl.body.php
<table>
<tr><td>menu</td><td>content</td></tr>
</table>
</body>
</html>
ºÐÇÒ±â´ÉÀ» »ç¿ëÇÒ ¶§µµ ¸ðµçÅÛÇø´¹®¹ýÀÌ À¯È¿Çϰí, ÅÛÇø´ÆÄÀÏ »ó´Ü¿¡ ¸ÅÅ©·Î ¶Ç´Â ÇÊÅͰ¡ Á¤ÀǵǾî ÀÖ´Ù¸é ºÐÇÒµÈ º¯È¯ÆÄÀÏ¿¡µµ ¶È°°ÀÌ Àû¿ëµË´Ï´Ù.
ºÐÇÒµÈ ÅÛÇø´ÆÄÀÏÀ» »ç¿ëÇÏ·Á¸é PHP ÆÄÀÏ¿¡ ´ÙÀ½°ú °°ÀÌ ÀÛ¼ºÇÕ´Ï´Ù.
index.php
...
$tpl->define(array(
    'header'=>'layout.tpl?head',
    'body'  =>'layout.tpl?body'
));
$tpl->print_('header');
flush();
...
...
...
$tpl->print_('body');
ÆÄÀϾÆÀ̵ð¿Í ºÐÇÒ¾ÆÀ̵ð´Â °°¾Æµµ, ´Þ¶óµµ µÇ¸ç, ±âº»º¯È¯ÆÄÀÏÀÎ layout.tpl.php ÆÄÀÏ ¿ª½Ã »ç¿ë°¡´ÉÇÕ´Ï´Ù.
 
2003-03-03 ~