Smarty
| Smarty | |
|---|---|
| Pembangun | Monte Ohrt, Messju Mohr |
| Pelancaran pertama | 2001 dan 2002 |
| Versi terkini/stabil | 2.6.19 (11 Feb 2008) |
| Ditulis dalam | PHP (mul) |
| Jenis | Template processor (en) |
| Genre | Enjin templat |
| Lesen | LGPL |
| Format fail boleh ditulis | |
| Format fail boleh dibaca | |
| Pautan berkaitan | |
| Tapak web | www.smarty.net |
| Repositori | |
| sunting · sunting di Wikidata | |
Smarty adalah satu sistem templat web berasaskan PHP. Smarty dipromosikan terutamanya sebagai sebuah alat untuk pengasingan usaha, yang merupakan strategi rekaan untuk sesetengah penggunaan.[1][2]
Contoh kod
Memandangkan Smarty mengasingkan PHP daripada HTML, maka terdapat dua fail:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>{$title_text}</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body> {* Ini adalah sedikit komen yang tidak akan dilihat di dalam sumber HTML *}
<p>{$body_text}</p>
</body><!-- Ini adalah sedikit komen yang akan dilihat di dalam sumber HTML -->
</html>
Dalam kod logik perniagaan Smarty boleh diset untuk menggunakan templat ini:
define('SMARTY_DIR', 'smarty-2.6.9/' );
require_once(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = './templates/';
$smarty->compile_dir = './templates/compile/';
$smarty->cache_dir = './templates/cache/';
$smarty->caching = false;
$smarty->error_reporting = E_ALL; // TINGGALKAN E_ALL SEMASA PEMBINAAN
$smarty->debugging = true;
$smarty->assign('title_text', 'TITLE: Ini adalah contoh asas Smarty ...');
$smarty->assign('body_text', 'BODY: Ini adalah mesej yang disetkan menggunakan assign()');
$smarty->display('index.tpl');
Catatan dan rujukan
- ^ Smarty mengasingkan kod PHP, (selalunya diwakilkan sebagai logik perniagaan) daripada HTML, (selalunya diwakilkan sebagai logik penyampaian).
- ^ Parr, Terence John (2004). Enforcing strict model-view separation in template engines. Proceedings of the 13th international conference on World Wide Web. 1-58113-844-X.
Pautan luar
- Tapak rasmi
- PHP Templating with Smarty oleh Cezar Floroiu - tutorial Smarty
- Smarty vs. XML/XSLT - dari DevPapers.com oleh Sergey Makogon
- Helaian Elat Smarty Helaian Elat Smarty untuk pereka templat dan pengatur cara
- Timestretch: PHP, MySQL, and Smarty Programming Diarkibkan 2007-06-27 di Wayback Machine - Lihat juga laman PHP2 untuk lebih lanjut.
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.
