Smarty

Smarty
PembangunMonte Ohrt, Messju Mohr
Pelancaran pertama2001 dan 2002 Sunting nilai ini di Wikidata
Versi terkini/stabil2.6.19 (11 Feb 2008)
Ditulis dalamPHP (mul) Terjemah Sunting nilai ini di Wikidata
JenisTemplate processor (en) Terjemahperisian bebaspustaka Sunting nilai ini di Wikidata
GenreEnjin templat
LesenLGPL
Format fail boleh ditulis
Senarai Senarai
Format fail boleh dibaca
Senarai Senarai
Pautan berkaitan
Tapak webwww.smarty.net
Repositori
sunting · sunting di Wikidata
Lihat pendokumenan templat ini
Lihat pendokumenan templat ini

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

  1. ^ Smarty mengasingkan kod PHP, (selalunya diwakilkan sebagai logik perniagaan) daripada HTML, (selalunya diwakilkan sebagai logik penyampaian).
  2. ^ 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

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.

  1. 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:
  2. 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.
  3. 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.
  4. 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.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.