smarty£º½â¾öphpºÍhtml´úÂë·ÖÀë¡£
1.1 smarty°²×°
1>http://smarty.php.net ÏÂÔØ
2>½âѹºó libsÎļþ¼Ð£¬smartyºËÐÄÎļþ¼Ð¡£¿½±´µ½ÄãµÄ¹¤×÷Ŀ¼¡£libs/Smarty.class.php
3>ºÍlibsƽ¼¶µÄĿ¼Ï£¬´´½¨Îļþ¼Ð
templates Íøҳģ°å£º*.html ***********
templates_c ±àÒëºóµÄ´úÂë
configs ÅäÖÃÎļþ
cache »º´æËùÓеÄÄ£°å
1.2 smartyµÄÅäÖÃ
1¡¢°¸Àý
smarty_02.php
require_once(¡°libs/Smarty.class.php¡±); //ÒýÈë
$smarty= new Smarty(); //ʵÀý»¯Ò»¸ö¶ÔÏó¡£
$smarty->assign(¡°awt¡±,$a); //Ϊģ°åµ±ÖеıäÁ¿¸³Öµ¡£Í¬Ê±¿ÉΪÊý×鸳ֵ
$smarty->display(¡°smarty_02.htm¡±); //Ä£°åÒ³µ÷ÓÃ
smarty_02.htm
¿ÉÒÔµ÷ÓÃÊý×é¡££¿£¿£¿£¿£¿£¿£¿£¿£¿
2¡¢smartyÅäÖá£
/* ¸Ä±äsmartyµÄÅäÖÃĿ¼½á¹¹¡£
$smarty->templates = ¡°a/templates¡±;
$smarty->templates_c = ¡°a/templates_c¡±;
$smarty->configs = ¡°a/configs¡±;
$smarty->cache = ¡°a/cache¡±;
*/
3¡¢Ä£°åÒ³µ±ÖУ¬Èç¹ûдÑùʽ£¬ÒòΪÓÐ{}£¬ÒýÆðÓïÒå»ìÂÒ£¬³ö´í¡£
1¡·Ð½¨cssÎļþ¡£°ÑÑùʽдÔÚcssÎļþÖУ¬±ÜÃâÁËÓïÒå»ìÂÒÁË¡£
ÔÚÄ£°åÖÐÈç¹ûµ÷ÓÃcssÑùʽ£¬ÊÇÒÔphpÎļþΪÖ÷¡£
2¡·¿ÉÒԸıäÄ£°åÖеĶ¨½ç·û¡°{}¡±==¡·¡°¡±
$smarty->left_delimiter = ¡°
$smarty->right_delimiter = ¡°}¨C>¡±;
smartyÓï·¨
1¡¢¿ØÖƽṹ
Ìõ¼þ1³ÉÁ¢µÄ´úÂë
Ìõ¼þ1³ÉÁ¢µÄ´úÂë
Ìõ¼þ3³ÉÁ¢µÄ´úÂë
¡¡¡.
ÒÔÉÏÌõ¼þ¶¼²»³ÉÁ¢Ö´ÐÐelse
2¡¢Ñ»·½á¹¹
while for do..while foreach
1¡·foreach
¸ñʽ£º
{foreach from=Êý×éÃû³Æ item=Êý×鵱ǰԪËØÃû}
Ñ»·Ìå¡£
{/foreach}
Àý£º//¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª-²âÊÔforeach¡ª¡ª¡ª¡ª¡ª¡ª¡ª¨C
2¡·section
¸ñʽ£º
{section name=¡±µ±Ç°ÔªËØ¡± loop=¡±Êý×éÃû³Æ¡±}
Ñ»·Ìå
{/section}
Àý£º//¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª-²âÊÔsection¡ª¡ª¡ª¡ª¡ª¡ª¡ª¨C