Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Smarty (template engine)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Smarty example == Since Smarty separates PHP from HTML, there are two files β one contains the presentation code: an HTML template, including Smarty variables and tags - <syntaxhighlight lang="smarty" inline>{$title_text|escape} {$body_html}</syntaxhighlight> - which might look like this: <syntaxhighlight lang="html+smarty"> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>{$title_text|escape}</title> </head> <body> {* This is a little comment that won't be visible in the HTML source *} {$body_html} </body> <!-- this is a little comment that will be seen in the HTML source --> </html> </syntaxhighlight> The [[business logic]] to use the Smarty template above could be as follows: <syntaxhighlight lang="php"> define('SMARTY_DIR', 'smarty-2.6.22/'); require_once(SMARTY_DIR . 'Smarty.class.php'); $smarty = new Smarty(); $smarty->template_dir = './templates/'; $smarty->compile_dir = './templates/compile/'; $smarty->assign('title_text', 'TITLE: This is the Smarty basic example ...'); $smarty->assign('body_html', '<p>BODY: This is the message set using assign()</p>'); $smarty->display('index.tpl'); </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)