mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 18:04:26 +02:00
*** empty log message ***
This commit is contained in:
36
QUICKSTART
36
QUICKSTART
@@ -54,7 +54,7 @@ directly from the browser, only Smarty calls them.)
|
|||||||
<?php
|
<?php
|
||||||
require("Smarty.class.php");
|
require("Smarty.class.php");
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign("Name","Fred");
|
$smarty->assign("Name","Ned");
|
||||||
$smarty->display("./templates/index.tpl");
|
$smarty->display("./templates/index.tpl");
|
||||||
?>
|
?>
|
||||||
|
|
||||||
@@ -71,19 +71,19 @@ $smarty->display("./templates/index.tpl");
|
|||||||
Now, view the index.php file from your web browser:
|
Now, view the index.php file from your web browser:
|
||||||
http://your.host.com/Smarty/index.php
|
http://your.host.com/Smarty/index.php
|
||||||
|
|
||||||
You should see "Hello, Fred!" in your browser. If not, retrace the steps above
|
You should see "Hello, Ned!" in your browser. If not, retrace the steps above
|
||||||
and make sure you follow the instructions exactly as they say. Also check the
|
and make sure you follow the instructions exactly as they say. Also check the
|
||||||
installation instructions in the documenation, and check your installation of
|
installation instructions in the documenation, and check your installation of
|
||||||
PHP to be sure things are setup properly.
|
PHP to be sure things are setup properly.
|
||||||
|
|
||||||
You see "Hello, Fred!" in your browser? Good!
|
You see "Hello, Ned!" in your browser? Good!
|
||||||
|
|
||||||
What happened here is Smarty took the index.tpl file and compiled it into a php
|
What happened here is Smarty took the index.tpl file and compiled it into a php
|
||||||
script which you can take a look at in the templates_c directory. Smarty will
|
script which you can take a look at in the templates_c directory. Smarty will
|
||||||
continue to use this compiled script until the index.tpl file is changed, then
|
continue to use this compiled script until the index.tpl file is changed, then
|
||||||
it will automatically recompile. What this means for you: forget about the
|
it will automatically recompile. What this means for you: forget about the
|
||||||
templates_c directory. Out of site, out of mind. You don't need to worry about
|
templates_c directory. Out of sight, out of mind. You don't need to worry about
|
||||||
it, Smarty takes care of this technical stuff. Out of curiosity you can see how
|
it, Smarty takes care of this technical stuff. Out of curiosity, you can see how
|
||||||
your templates look as compiled php scripts, but please don't touch them!
|
your templates look as compiled php scripts, but please don't touch them!
|
||||||
|
|
||||||
Now that we have Smarty functioning properly, let's get into the guts of Smarty
|
Now that we have Smarty functioning properly, let's get into the guts of Smarty
|
||||||
@@ -94,17 +94,17 @@ the most important features of Smarty.
|
|||||||
ASSIGNING VARIABLES
|
ASSIGNING VARIABLES
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
Assigning variables to the template are very similar to the ways you see other
|
Assigning variables to the template is very similar to the ways other template
|
||||||
template engines assign them. Example:
|
engines do it. Example:
|
||||||
|
|
||||||
|
|
||||||
--------- index.php --------
|
--------- index.php --------
|
||||||
<?php
|
<?php
|
||||||
require("Smarty.class.php");
|
require("Smarty.class.php");
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign("Name","Fred");
|
$smarty->assign("Name","Ned");
|
||||||
$smarty->assign(array(
|
$smarty->assign(array(
|
||||||
"FirstName" => "Fred",
|
"FirstName" => "Ned",
|
||||||
"LastName" => "Flanders",
|
"LastName" => "Flanders",
|
||||||
"Address" => "Springfield"
|
"Address" => "Springfield"
|
||||||
));
|
));
|
||||||
@@ -125,7 +125,7 @@ $smarty->display("./templates/index.tpl");
|
|||||||
</HTML>
|
</HTML>
|
||||||
|
|
||||||
|
|
||||||
You can assign variables either single fasion, or as an associative array. There
|
You can assign variables either one by one, or as an associative array. There
|
||||||
is also a way to append to assigned variables. See the documentation for
|
is also a way to append to assigned variables. See the documentation for
|
||||||
details.
|
details.
|
||||||
|
|
||||||
@@ -141,9 +141,9 @@ templates/footer.tpl.
|
|||||||
<?php
|
<?php
|
||||||
require("Smarty.class.php");
|
require("Smarty.class.php");
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign("Name","Fred");
|
$smarty->assign("Name","Ned");
|
||||||
$smarty->assign(array(
|
$smarty->assign(array(
|
||||||
"FirstName" => "Fred",
|
"FirstName" => "Ned",
|
||||||
"LastName" => "Flanders",
|
"LastName" => "Flanders",
|
||||||
"Address" => "Springfield"
|
"Address" => "Springfield"
|
||||||
));
|
));
|
||||||
@@ -181,7 +181,7 @@ $title is empty, the text "Home Page" will be printed instead of nothing.
|
|||||||
IF/ELSEIF/ELSE
|
IF/ELSEIF/ELSE
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
This systax is very straight forward. The documention goes into depth on this
|
This syntax is very straightforward. The documention goes into depth on this
|
||||||
one, so you should be able to do just about anything you want to with it.
|
one, so you should be able to do just about anything you want to with it.
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@@ -189,8 +189,8 @@ Example:
|
|||||||
{include file="header.tpl" title="Home Page"}
|
{include file="header.tpl" title="Home Page"}
|
||||||
{if $Name eq ""}
|
{if $Name eq ""}
|
||||||
Hello, Noname!<br>
|
Hello, Noname!<br>
|
||||||
{elseif $Name eq "Fred"}
|
{elseif $Name eq "Ned"}
|
||||||
Hello, Frederick!<br>
|
Hello, Neddy!<br>
|
||||||
{else}
|
{else}
|
||||||
Hello, {$Name}<br>
|
Hello, {$Name}<br>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -212,7 +212,7 @@ times the section will loop.
|
|||||||
<?php
|
<?php
|
||||||
require("Smarty.class.php");
|
require("Smarty.class.php");
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign("FirstName",array("Fred","Bart","Montgomery"));
|
$smarty->assign("FirstName",array("Ned","Bart","Montgomery"));
|
||||||
$smarty->assign("LastName",array("Flanders","Simpson","Burns"));
|
$smarty->assign("LastName",array("Flanders","Simpson","Burns"));
|
||||||
$smarty->display("./templates/index.tpl");
|
$smarty->display("./templates/index.tpl");
|
||||||
?>
|
?>
|
||||||
@@ -243,7 +243,7 @@ You can also do complex nested sections, like so:
|
|||||||
<?php
|
<?php
|
||||||
require("Smarty.class.php");
|
require("Smarty.class.php");
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign("FirstName",array("Fred","Bart","Montgomery"));
|
$smarty->assign("FirstName",array("Ned","Bart","Montgomery"));
|
||||||
$smarty->assign("LastName",array("Flanders","Simpson","Burns"));
|
$smarty->assign("LastName",array("Flanders","Simpson","Burns"));
|
||||||
$smarty->assign("ContactNames",array(
|
$smarty->assign("ContactNames",array(
|
||||||
array("email","home","cell"),
|
array("email","home","cell"),
|
||||||
@@ -278,6 +278,6 @@ $smarty->display("./templates/index.tpl");
|
|||||||
{include file="footer.tpl"}
|
{include file="footer.tpl"}
|
||||||
|
|
||||||
|
|
||||||
This should be enough to get your feet wet. Also check out config file
|
This should be enough to get your feet wet. Also, check out config file
|
||||||
variables, built-in functions, custom functions, variable modifiers, all sorts
|
variables, built-in functions, custom functions, variable modifiers, all sorts
|
||||||
of good stuff. Now go read the documentation, and Good Luck!
|
of good stuff. Now go read the documentation, and Good Luck!
|
||||||
|
@@ -127,7 +127,7 @@ function smarty_mod_strip_tags($string, $replace_with_space = true)
|
|||||||
return strip_tags($string);
|
return strip_tags($string);
|
||||||
}
|
}
|
||||||
|
|
||||||
function smarty_mod_default($string,$default="")
|
function smarty_mod_default($string, $default="")
|
||||||
{
|
{
|
||||||
if(empty($string))
|
if(empty($string))
|
||||||
return $default;
|
return $default;
|
||||||
|
Reference in New Issue
Block a user