-
include_once("smarty/Smarty.class.php");
- $smarty=new Smarty();
- $smarty->config_dir="smarty/Config_File.class.php";
- $smarty->caching=false;
- $smarty->template_dir="./templates";
- $smarty->compile_dir="./templates_c";
- $smarty->cache_dir="./smarty_cache ";
- $smarty->left_delimiter="{";
- $smarty->right_delimiter="}";
- ?>
Copy the code
3. Write the php file index.php
-
include("smarty_inc.php");
- $name[]=array("name"=>"News First","date"=>"2008- 1-1");
- $name[]=array("name"=>"News Article 2","date"=>"2008-2-1");
- $name[]=array( "name"=>"News Article 3","date"=>"2008-3-1");
- $row=array("title","author");
- $smarty->assign ("title",$name);
- $smarty->assign("row",$row);
- $smarty->display("index.html")
- ?>
Copy code
4. Write index.html in the templates folder index.html
- {$row[0]}|{$row[1]}
- {section name=list loop=$title}
- {$title[list].name}--{$title[list].date}
- {/section}
Copy code
5. Use variable operators index.php
-
include("smarty_inc.php");
- $value="it is Work and, it Is video";
- $smarty->assign("name",$value) ;
- $smarty->display("index.html")
- ?>
Copy code
index.html
- Original content: {$name}
- {$name|capitalize}
- {$name|cat:"Demo"}
- { $smarty.now|date_format:'%Y-%M-%D'};
- {$name|repalce:"is":"***"};
- {$name|truncate}
Copy code
6. foreach index.php
-
include("smarty_inc.php");
- $value=array(4,5,6,7);
- $value_key=array('a'=>"PHP" ,'b'=>"JAVA",'c'=>"C++");
- $smarty->assign("name",$value);
- $smarty->assign("name_key", $value_key);
- $smarty->display("index.html")
- ?>
Copy code
index.html
- {include file="header.html"}
- {foreach from=$name item=id}
- Array content: {$id}
- {/foreach}
- {foreach from=$name item=id key=k}
- Array content: {$k}--{$id}
- {/foreach}
Copy code
7.literal When curly brackets appear, if you use javascript, you can use literal for text processing 8.strip Optimize the page to remove the spaces in the tags. Make it difficult for people to steal easily 9. Cache basic configuration:
-
include_once("smarty/Smarty.class.php");
- $smarty=new Smarty();
- $smarty->config_dir="smarty/Config_File.class.php" ;
- $smarty->caching=true;
- $smarty->template_dir="./templates";
- $smarty->compile_dir="./templates_c";
- $smarty->cache_dir="./ smarty_cache";
- $smarty->cache_lifetime=60;
- $smarty->left_delimiter="{";
- $smarty->right_delimiter="}";
- ?>
Copy code
With ID cache
-
include("smarty_inc.php");
- $id=$_GET[id];
- $value=array(4,5,6,7);
- $smarty-> ;assign("name",$value);
- $smarty->assign("id",$id);
- $smarty->display("index.html",$id);
- ?>
Copy code
Clear cache and partial cache
-
include("smarty_inc.php");
- $id=$_GET[id];
- $value=array(4,5,6,7);
- //Use insert Local cache:
- function insert_shijian(){
- return date("Y-m-d H:m:s");
- }
- $smarty->assign("name",$value);
- $smarty->assign( "id",$id);
- $smarty->display("index.html",$id);
- //Delete the cache with ID$smarty->clear_cache('index.html',$id) ;
- //Delete all cache $smarty->clear_all_cache();
- ?>
Copy code
|