Home  >  Article  >  Backend Development  >  Laughing about Smarty technology configuration and application

Laughing about Smarty technology configuration and application

WBOY
WBOYOriginal
2016-07-25 09:05:52907browse
  1. <{$title }>
  2. <{$content}>
Copy code

Save In the templates directory.

5. Create a new file template configuration file: config.php

  1. include "../libs/Smarty.class.php";
  2. $NowPathArray=explode("test",str_replace("\","/",dirname(__FILE__)) ) ;
  3. @define("root_path", $NowPathArray[0]);
  4. @define('__SITE_ROOT', root_path."test");
  5. $tpl = new Smarty();
  6. $tpl->template_dir = __SITE_ROOT . "/templates/";
  7. $tpl->compile_dir = __SITE_ROOT . "/templates_c/";
  8. $tpl->config_dir = __SITE_ROOT . "/configs/";
  9. $tpl->cache_dir = __SITE_ROOT . " /cache/";
  10. $tpl->left_delimiter = '<{';
  11. $tpl->right_delimiter = '}>';
  12. ?>
Copy the code

and save it in the home directory in test.

6. Create a new file test.php in test

  1. require "config.php";
  2. $tpl->assign("title", "The test was successful, this is the title");
  3. $tpl->assign(" content", "This is the content");
  4. $tpl->display('test.htm');
  5. ?>
Copy code

7: Testing test.php in the browser displays:

This is the content

Congratulations, the configuration is successful. Otherwise, it fails, check again to see if it is as I said.

Tips1: In order to use Smarty technology globally on the website, we can modify the

; Windows: "path1;path2" include_path = ".;c:phpincludes"

Change to: ------------------> ; Windows: "path1;path2" include_path = ".;c:phpincludes;d:webwebphplibs" When using templates, use them in the same way as before, do not include "../libs/Smarty.class.php"; It can be used directly.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn