mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
remove some files already in docs or elsewhere
This commit is contained in:
11
AUTHORS
11
AUTHORS
@@ -1,11 +0,0 @@
|
||||
Monte Ohrt <monte@ispi.net>
|
||||
- idea of compiling into PHP scripts
|
||||
- initial implementation
|
||||
- documentation
|
||||
|
||||
Andrei Zmievski <andrei@php.net>
|
||||
- rewrote parser from scratch
|
||||
- maintains code base
|
||||
- plugin architecture
|
||||
- wrote Config_File class
|
||||
- documentation
|
12
BUGS
12
BUGS
@@ -1,14 +1,4 @@
|
||||
There are some bugs in older versions of PHP that cause problems with Smarty.
|
||||
preg_replace() had a parameter added in 4.0.2 that is needed for Smarty.
|
||||
preg_grep() previous to 4.0.4 has a bug which Smarty has a built-in workaround
|
||||
for. PHP 4.0.4 has a bug with user callbacks which would cause this syntax in
|
||||
Smarty to crash PHP: {$varname|@modname} Use PHP 4.0.4pl1 to fix this, or avoid
|
||||
using the "@" with modifiers. if you are passing variables to {include}
|
||||
statements, you will need PHP 4.0.4 or later, which requires the use of
|
||||
get_defined_vars() function. Some versions of Windows 2k have a problem with
|
||||
flock(). Comment out the flock() command in _write_file to get around this.
|
||||
|
||||
To be absolutely safe, use 4.0.6 or later with Smarty.
|
||||
Smarty is supported only in PHP 4.0.6 or later.
|
||||
|
||||
Smarty versions previous to 2.0 require the PEAR libraries. Be sure to include
|
||||
the path to the PEAR libraries in your php include_path. Config_file.class.php
|
||||
|
23
CREDITS
23
CREDITS
@@ -1,23 +0,0 @@
|
||||
Monte Ohrt <monte@ispi.net>:
|
||||
Concepted compiling templates into PHP scripts, wrote initial "proof of
|
||||
concept" implementation, and maintains documentation & code base.
|
||||
|
||||
Andrei Zmievski <andrei@php.net>:
|
||||
Rewrote parser from scratch, developed plugin architecture, reorganized
|
||||
documentation, and maintains code base.
|
||||
|
||||
Anne Holz <anne@ispi.net>:
|
||||
Provided creative input with respect to web design.
|
||||
|
||||
Frank Kromann <fmk@php.net>:
|
||||
Idea of custom function ability.
|
||||
|
||||
A special thanks goes to the people that have contributed other templating
|
||||
solutions to the PHP community which we learned a lot from.
|
||||
|
||||
A special thanks goes to the members of the php-template mailing list and the
|
||||
smarty mailing list, too numerous to list, who are sharing and bringing many
|
||||
ideas to the table and contributing source code.
|
||||
|
||||
Rasmus Lerdorf <rasmus@php.net>: For starting what eventually became the
|
||||
coolest programming language ever.
|
375
QUICKSTART
375
QUICKSTART
@@ -1,375 +0,0 @@
|
||||
SMARTY QUICKSTART GUIDE
|
||||
-----------------------
|
||||
|
||||
Welcome to the Smarty QUICKSTART guide. This guide is to help you immediately
|
||||
get your feet wet in Smarty, get a feel for how it works and if it will work
|
||||
for you.
|
||||
|
||||
We make a few assumptions here, such as you already have PHP installed on your
|
||||
web server, you know the basics of unix file permissions, the basics of PHP and
|
||||
how it works, etc. If you are using Smarty in a non-unix environment, you
|
||||
should understand the difference in your OS regarding file permissions.
|
||||
|
||||
INSTALLATION
|
||||
------------
|
||||
|
||||
**
|
||||
Note: this installation procedure is quick and dirty, it is meant to get Smarty
|
||||
working just to see it work. The installation procedure from the Smarty
|
||||
documentation is much more complete, setting up Smarty in a way that is
|
||||
reusable for your applications and away from your web server document root.
|
||||
**
|
||||
|
||||
Unpack the Smarty tarball. You will see some files: Smarty.class.php,
|
||||
Smarty_Compiler.class.php, Config_File.class.php, debug.tpl and a "plugins"
|
||||
directory. You will need all of these files somewhere in your PHP include path,
|
||||
so when you call require("Smarty.class.php") from within your application, it
|
||||
can find the class. Alternatively, you can define the SMARTY_DIR constant in
|
||||
your application, and Smarty will use that directory as the path to the Smarty
|
||||
class files. Be sure the SMARTY_DIR path ends with a slash!
|
||||
|
||||
Now change directories somewhere inside of your web server document root. For
|
||||
this quick install guide, we'll create a directory under the document root
|
||||
named "Smarty", and put all of our work here.
|
||||
|
||||
$> cd /home/htdocs
|
||||
$> mkdir Smarty
|
||||
$> cd Smarty
|
||||
|
||||
now, we need to create a few directories for Smarty to use:
|
||||
|
||||
$> mkdir templates
|
||||
$> mkdir templates_c
|
||||
$> mkdir configs
|
||||
|
||||
Smarty needs to be able to write to the templates_c directory. It is
|
||||
recommended that you change the ownership and write permissions such that the
|
||||
web server user (usually "nobody:nobody", Mac OS X uses "www:www") has write
|
||||
access to this directory. You can chmod 777 the directory, but be aware of
|
||||
security concerns on multi-user systems. See the documentation for more info on
|
||||
this.
|
||||
|
||||
$> chown nobody:nobody templates_c
|
||||
$> chmod 700 templates_c
|
||||
$> ls -l
|
||||
drwxrwxr-x 2 user group 512 Jan 18 14:18 configs/
|
||||
drwxrwxr-x 2 user group 512 Jan 18 14:18 templates/
|
||||
drwx------ 2 nobody nobody 512 Jan 18 14:18 templates_c/
|
||||
|
||||
Or alternately (less secure):
|
||||
|
||||
$> chmod 777 templates_c
|
||||
$> ls -l
|
||||
drwxrwxr-x 2 user group 512 Jan 18 14:18 configs/
|
||||
drwxrwxr-x 2 user group 512 Jan 18 14:18 templates/
|
||||
drwxrwxrwx 2 user group 512 Jan 18 14:18 templates_c/
|
||||
|
||||
Now we need to create two files, index.php and templates/index.tpl. index.php
|
||||
is the file that we will be calling from our web browser. index.tpl is the file
|
||||
that Smarty will use as its template file. (Smarty template files are never
|
||||
accessed directly from the browser, only the Smarty class accesses them.)
|
||||
|
||||
|
||||
--------- index.php --------
|
||||
<?php
|
||||
require("Smarty.class.php");
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign("Name","Ned");
|
||||
$smarty->display("index.tpl");
|
||||
?>
|
||||
|
||||
|
||||
--------- templates/index.tpl --------
|
||||
<HTML>
|
||||
<TITLE>Hello</TITLE>
|
||||
<BODY>
|
||||
Hello, {$Name}!
|
||||
</BODY>
|
||||
</HTML>
|
||||
|
||||
|
||||
Now, view the index.php file from your web browser:
|
||||
http://your.host.com/Smarty/index.php
|
||||
|
||||
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
|
||||
installation instructions in the documenation, and check your installation of
|
||||
PHP to be sure things are setup properly. If your still having problems, ask a
|
||||
question on the mailing list, which you can find in the FAQ.
|
||||
|
||||
You see "Hello, Ned!" in your browser? Good!
|
||||
|
||||
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
|
||||
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
|
||||
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 your templates look as compiled php scripts, but please don't edit them!
|
||||
|
||||
Now that we have Smarty functioning properly, let's take a look at a few
|
||||
features of the template language.
|
||||
|
||||
ASSIGNING VARIABLES
|
||||
-------------------
|
||||
|
||||
Assigning variables to the template is fairly straight forward. Example:
|
||||
|
||||
|
||||
--------- index.php --------
|
||||
<?php
|
||||
require("Smarty.class.php");
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign("Name","Ned");
|
||||
$smarty->assign(array(
|
||||
"FirstName" => "Ned",
|
||||
"LastName" => "Flanders",
|
||||
"Address" => "Springfield"
|
||||
));
|
||||
$zipcode = "55555";
|
||||
$smarty->assign("Zipcode",$zipcode);
|
||||
$smarty->display("index.tpl");
|
||||
?>
|
||||
|
||||
|
||||
--------- templates/index.tpl --------
|
||||
<HTML>
|
||||
<TITLE>Hello</TITLE>
|
||||
<BODY>
|
||||
Hello, {$Name}!<br>
|
||||
{$FirstName}, {$LastName}<br>
|
||||
{$Address}, {$Zipcode}
|
||||
</BODY>
|
||||
</HTML>
|
||||
|
||||
|
||||
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
|
||||
details.
|
||||
|
||||
INCLUDE
|
||||
-------
|
||||
|
||||
Now, let's see how Smarty can be used to include other template files. This is
|
||||
handy if you have repetitive template data, such as headers and footers. You
|
||||
will need to create a couple more template files: templates/header.tpl and
|
||||
templates/footer.tpl.
|
||||
|
||||
--------- index.php --------
|
||||
<?php
|
||||
require("Smarty.class.php");
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign("Name","Ned");
|
||||
$smarty->assign(array(
|
||||
"FirstName" => "Ned",
|
||||
"LastName" => "Flanders",
|
||||
"Address" => "Springfield"
|
||||
));
|
||||
$zipcode = "55555";
|
||||
$smarty->assign("Zipcode",$zipcode);
|
||||
$smarty->display("index.tpl");
|
||||
?>
|
||||
|
||||
|
||||
--------- templates/index.tpl --------
|
||||
{include file="header.tpl" title="Home Page"}
|
||||
Hello, {$Name}!<br>
|
||||
{$FirstName}, {$LastName}<br>
|
||||
{$Address}, {$Zipcode}
|
||||
{include file="footer.tpl"}
|
||||
|
||||
--------- templates/header.tpl --------
|
||||
<HTML>
|
||||
<TITLE>{$title|default:"no title"}</TITLE>
|
||||
<BODY>
|
||||
|
||||
--------- templates/footer.tpl --------
|
||||
</BODY>
|
||||
</HTML>
|
||||
|
||||
|
||||
Notice we are passing the variable "title" when we include the header.tpl file.
|
||||
You can pass as many variables as you want. The included file inherits all the
|
||||
current template vars, plus any that are passed to it. The passed variables are
|
||||
only available within the scope of the included file (and any files it may
|
||||
include.) Also notice the way the $title variable is printed to the template.
|
||||
It uses a variable modifier called "default". Printing {$title|default:"no
|
||||
title"} means that if the value of $title is empty, the text "no title" will be
|
||||
printed instead of nothing.
|
||||
|
||||
IF/ELSEIF/ELSE
|
||||
--------------
|
||||
|
||||
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.
|
||||
Example:
|
||||
|
||||
--------- templates/index.tpl --------
|
||||
{include file="header.tpl" title="Home Page"}
|
||||
{if $Name eq ""}
|
||||
Hello, Noname!<br>
|
||||
{elseif $Name eq "Ned"}
|
||||
Hello, Neddy!<br>
|
||||
{else}
|
||||
Hello, {$Name}<br>
|
||||
{/if}
|
||||
|
||||
{$FirstName}, {$LastName}<br>
|
||||
{$Address}, {$Zipcode}
|
||||
{include file="footer.tpl"}
|
||||
|
||||
|
||||
SECTIONS (Dynamic Blocks)
|
||||
-------------------------
|
||||
|
||||
Looping through arrays of data in Smarty is relatively simple, using the
|
||||
{section} function. Two attributes are required: name and loop. name is the name
|
||||
of the section, and loop is the name of the array that determines the number of
|
||||
times the section will loop.
|
||||
|
||||
--------- index.php --------
|
||||
<?php
|
||||
require("Smarty.class.php");
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign("FirstName",array("Ned","Bart","Montgomery"));
|
||||
$smarty->assign("LastName",array("Flanders","Simpson","Burns"));
|
||||
$smarty->display("index.tpl");
|
||||
?>
|
||||
|
||||
--------- templates/index.tpl --------
|
||||
{include file="header.tpl" title="Home Page"}
|
||||
{section name=people loop=$FirstName}
|
||||
{$smarty.section.people.iteration} {$FirstName[people]} {$LastName[people]}<br>
|
||||
{sectionelse}
|
||||
There are no values to loop through.
|
||||
{/section}
|
||||
<p>
|
||||
There were {$smarty.section.people.loop} names in this list.
|
||||
{include file="footer.tpl"}
|
||||
|
||||
Here we are introducing the {$smarty} variable, which is used to reference
|
||||
values internal to the template. Notice that when printing variables inside of
|
||||
the section, the section name must be referenced in the name of the variable
|
||||
being displayed. This lets Smarty understand that you want to print the value
|
||||
in the array position indexed by the current loop value. There are also internal
|
||||
template variables available within the section that display the loop iteration
|
||||
and the total number of times the section is looped. Also note the
|
||||
{sectionelse}. This would have been displayed if looped array $FirstName was
|
||||
empty.
|
||||
|
||||
You can access keys of arrays with this syntax:
|
||||
|
||||
--------- index.php --------
|
||||
<?php
|
||||
require("Smarty.class.php");
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign(array("ContactInfo" => array(
|
||||
array("FirstName" => "Ned","LastName" => "Flanders"),
|
||||
array("FirstName" => "Monty","LastName" => "Burns")
|
||||
)
|
||||
));
|
||||
$smarty->display("index.tpl");
|
||||
?>
|
||||
|
||||
--------- templates/index.tpl --------
|
||||
{include file="header.tpl" title="Home Page"}
|
||||
{section name=people loop=$ContactInfo}
|
||||
{$ContactInfo[people].FirstName}
|
||||
{$ContactInfo[people].LastName}<br>
|
||||
{sectionelse}
|
||||
There are no values to loop through.
|
||||
{/section}
|
||||
<p>
|
||||
There were {$smarty.section.people.loop} names in this list.
|
||||
{include file="footer.tpl"}
|
||||
|
||||
|
||||
You can also do complex nested sections, like so:
|
||||
|
||||
--------- index.php --------
|
||||
<?php
|
||||
require("Smarty.class.php");
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign("FirstName",array("Ned","Bart","Montgomery"));
|
||||
$smarty->assign("LastName",array("Flanders","Simpson","Burns"));
|
||||
$smarty->assign("ContactNames",array(
|
||||
array("email","home","cell"),
|
||||
array("email","home"),
|
||||
array("email","home","fax")
|
||||
));
|
||||
$smarty->assign("ContactVals",array(
|
||||
array("ned@simpsons.com","555-666-7777","555-444-3333"),
|
||||
array("bart@simpsons.com","555-111-2222"),
|
||||
array("monty@simpsons.com","555-888-9999","555-234-5678"),
|
||||
));
|
||||
|
||||
$smarty->display("index.tpl");
|
||||
?>
|
||||
|
||||
--------- templates/index.tpl --------
|
||||
{include file="header.tpl" title="Home Page"}
|
||||
{section name=people loop=$FirstName}
|
||||
{$smarty.section.people.rownum} {$FirstName[people]} {$LastName[people]}<br>
|
||||
{section name=contacts loop=$ContactNames[people]}
|
||||
{* for fun, lets bold every other row *}
|
||||
{if $smarty.section.contacts.rownum is even}<b>{/if}
|
||||
{$ContactNames[people][contacts]}: {$ContactVals[people][contacts]}<br>
|
||||
{if $smarty.section.contacts.rownum is even}</b>{/if}
|
||||
{/section}
|
||||
<br>
|
||||
{sectionelse}
|
||||
There are no values to loop through.
|
||||
{/section}
|
||||
<p>
|
||||
There were {$smarty.section.people.loop} names in this list.
|
||||
{include file="footer.tpl"}
|
||||
|
||||
|
||||
FOREACH
|
||||
-------
|
||||
|
||||
There is also an alternative way to loop through associative arrays that may be
|
||||
a bit easier for you, especially if you only need to loop over one variable.
|
||||
|
||||
Here's an example that works with the default index.php that comes with Smarty:
|
||||
|
||||
{foreach name=outer item=contact from=$contacts}
|
||||
{foreach key=key item=item from=$contact}
|
||||
{$smarty.foreach.outer.iteration}. contact {$key}: {$item}
|
||||
{/foreach}
|
||||
{foreachelse}
|
||||
no contacts
|
||||
{/foreach}
|
||||
|
||||
Possible attributes:
|
||||
|
||||
from: the array you are looping through
|
||||
item: the name of the variable that is the current element
|
||||
key: the name of the variable that is the current key (optional)
|
||||
name: the name of the of foreach (optional)
|
||||
|
||||
The 'name' has to be used if you want to refer to any of the foreach
|
||||
properties.
|
||||
|
||||
Properties (if 'name' is used):
|
||||
|
||||
name: the name of foreach
|
||||
iteration: current iteration
|
||||
total: total number of iterations
|
||||
first: if it's first iteration
|
||||
last: it it's last iteration
|
||||
show: if foreach was shown at all
|
||||
|
||||
Here's another neat example, dumps all properties of foreach:
|
||||
|
||||
{foreach name=outer item=contact from=$contacts}
|
||||
{foreach key=key item=item from=$smarty.foreach.outer}
|
||||
{$key}: {$item}
|
||||
{/foreach}
|
||||
{/foreach}
|
||||
|
||||
|
||||
This should be enough to get your feet wet. Also, check out config file
|
||||
variables, built-in functions, custom functions, variable modifiers, all sorts
|
||||
of good stuff. Now go read the documentation, join the mailing list and have
|
||||
fun!
|
1
README
1
README
@@ -9,7 +9,6 @@ AUTHORS:
|
||||
Monte Ohrt <monte@ispi.net>
|
||||
Andrei Zmievski <andrei@php.net>
|
||||
|
||||
|
||||
MAILING LISTS:
|
||||
|
||||
We have a few mailing lists. "general" for you to share your ideas or ask
|
||||
|
21
RESOURCES
21
RESOURCES
@@ -1,21 +0,0 @@
|
||||
Smarty Resources on the Web:
|
||||
(if you have something to add, e-mail monte at ispi dot net)
|
||||
|
||||
Home Page:
|
||||
http://smarty.php.net
|
||||
http://www.phpinsider.com/php/code/Smarty
|
||||
|
||||
Tutorials:
|
||||
http://www.zend.com/zend/tut/tutsweatpart1.php
|
||||
|
||||
Scripts:
|
||||
http://www.mapledesign.co.uk/coding/smarty_table.php
|
||||
|
||||
Software Using Smarty:
|
||||
http://phplens.com/
|
||||
http://www.x-cart.com/
|
||||
http://www.moregroupware.org/
|
||||
|
||||
Misc:
|
||||
http://freshmeat.net/projects/smarty/
|
||||
http://www.hotscripts.com/Detailed/8817.html
|
81
TESTIMONIALS
81
TESTIMONIALS
@@ -1,81 +0,0 @@
|
||||
"I just got my first paying contract for a local small business and in my
|
||||
program I'm using Smarty. Smarty is an absolute joy to work with -
|
||||
at first, I didn't like the idea of populating variables/arrays and then
|
||||
assigning those directly (since I'd been using FastTemplates for so long),
|
||||
but after using this system for a while, I don't think I can ever go back
|
||||
(I even switched my Perl template engine to HTML-Template-2.4 which
|
||||
operates on the same concepts). Anyway, thanks for saving me time and
|
||||
headache!"
|
||||
|
||||
-- Brian E. Lozier
|
||||
|
||||
|
||||
"Smarty is usually described as 'complex', I can testify this is not true.
|
||||
What is true is that the Smarty learning curve is longer than any other
|
||||
stuff, but on the other side Smarty is the one and only system that allows
|
||||
a single guy to build and manage a website with hundreds of templates,
|
||||
sophisticated user management, editorial publishing and a lot of other
|
||||
stuff without any problem.
|
||||
|
||||
I tried a lot of other solutions, I tried to extend prepackaged solutions
|
||||
(the famous nuke-like family).. nothing comes close to Smarty.
|
||||
|
||||
And about the 'complex' aspect.. I'm not even a developer. I became a
|
||||
so-called one because of my site but in reality I'm not a developer."
|
||||
|
||||
-- Luc Saint-Elie
|
||||
|
||||
|
||||
"I just wanted to say that I'm really impressed with Smarty. Coming
|
||||
from an enterprise Java background I was frustrated with the lack of
|
||||
templating APIs that existed for PHP. While there are plenty of out of
|
||||
the box 'tools' that existed, few were intended to be frameworks that
|
||||
people could extend; Smarty is an excellent example of an extensible
|
||||
PHP application with it's pluggable functions, modifiers, etc."
|
||||
|
||||
-- Mark Priatel
|
||||
|
||||
|
||||
"I was working with PHPLIB-templates first, then after beeing frustrated
|
||||
about how to handle conditional output with that, I tried IT[X], which
|
||||
helps a lot, compared to phplib-templates, but after short time you get
|
||||
even more frustrated about the restrictions and problems you have to deal
|
||||
with, too many pitfalls nobody wrote anywhere about. And now Smarty, man
|
||||
this is a real big step! It is so great to work with it, finally I realize,
|
||||
how much time I spent building everything around a half-finished
|
||||
template-engine, asking myself with every new idea 'how to get it to work
|
||||
with that'.
|
||||
Smarty is a real good helper, it extends my possibilities without
|
||||
having to deal with any restrictions - my english is too bad, to
|
||||
express that positive vibrations I feel..."
|
||||
|
||||
-- Jones Down
|
||||
|
||||
|
||||
"We've had great results with a Smarty/Zend Accelerator versus
|
||||
FastTemplate/Zend Accelerator benchmark. Thanks to Smarty I'm going to
|
||||
have to work late all week re-writing our FastTemplate site :)"
|
||||
|
||||
-- Robert V. Zwink
|
||||
|
||||
|
||||
"Hello, sorry for my english, i'm french ...
|
||||
|
||||
I've just discovered SMARTY ...
|
||||
I've tested it ...
|
||||
What a wonderful well-thinked product !!!
|
||||
I am a fan of XML/XSLT, but with server-side script ; it's not "easy" to
|
||||
build something strong.
|
||||
But with smarty ; it's wonderful to separate the look from the code ... and
|
||||
such easy ...
|
||||
I've tested others templates system, no-one is better ...
|
||||
I can't find my words in english to describe how many this product is
|
||||
WELL-THINKED, and such good ...
|
||||
|
||||
it's GREAT GREAT GREAT !
|
||||
And will use it for ever ...
|
||||
|
||||
thanx A LOT for your good work !!!
|
||||
you'll must have a "medal of honnor" for this product !"
|
||||
|
||||
-- Marc Lentz
|
Reference in New Issue
Block a user