smarty模板的作用|smarty模板中怎么使用fckeditor

时间:2017-10-08  来源:smarty模板  阅读:

在Smarty中调用FCKeditor的文件

 代码如下
//FCKeditor in smarty
 //Rossy.cn@gmail.com
 //2007-09-12 13:14
 
require_once("conn.php");
 require_once("class/Smarty.class.php");
 
$smarty = new Smarty();
 $smarty->template_dir = "../templates";
 $smarty->compile_dir  = "../templates_c";
 $smarty->left_delimiter = "<{";
 $smarty->right_delimiter = "}>";
 
$editor = new FCKeditor("Content") ;
 $editor->BasePath   = "../FCKeditor/";
 $editor->ToolbarSet = "Basic";
 $editor->Value      = "";
 $FCKeditor = $editor->CreateHtml();
 
$smarty->assign("Title","Rossy is here waiting for you");
 $smarty->assign("FCKeditor",$FCKeditor);  
 $smarty->display("template.tpl");

但,运用这一种方法在编辑资料的时候竟然FCKeditor传不了值,只是生成了一个空值的编辑器,所以只能换一种方法:

 代码如下

//FCKeditor in smarty
 //Rossy.cn@gmail.com
 //2007-09-12 13:18
 
require_once("conn.php");
 require_once("class/Smarty.class.php");
 
$smarty = new Smarty();
 $smarty->template_dir = "../templates";
 $smarty->compile_dir  = "../templates_c";
 $smarty->left_delimiter = "<{";
 $smarty->right_delimiter = "}>";
 
$editor = new FCKeditor("Content") ;
 $editor->BasePath   = "../FCKeditor/";
 $editor->ToolbarSet = "Basic";
 $editor->Value      = "Here is a example of smarty and FCKeditor";
 
$smarty->assign("Title","Rossy is here waiting for you");
 $smartyl->assign_by_ref("FCKeditor",$editor);
 $smarty->display("template.tpl");

调用

 代码如下



example of smarty use fckeditor

 

Example


title:<{$Title}>



content:


<{$FCKeditor}>



例2

这里我通过smarty的插件机制,可以更方便的在smarty中集成fckeditor,在smarty的plugin目录中新建文件function.fck.php

内容如下

 代码如下

function smarty_function_fck($params, &$smarty)
{
 if(!isset($params["InstanceName"]) || empty($params["InstanceName"]))
 {
  $smarty->trigger_error(‘fckeditor: required parameter “InstanceName” missing’);
 }

 static $base_arguments = array();
 static $config_arguments = array();

 if(!count($base_arguments))
  $init = TRUE;
 else
  $init = FALSE;

 if(isset($params["BasePath"]))
 {
  $base_arguments["BasePath"] = $params["BasePath"];
 }
 else if(empty($base_arguments["BasePath"]))
 {

//这里设置默认的fck所在的目录,相对于要使用fck的程序的目录
  $base_arguments["BasePath"] = ‘../plugins/fckeditor/’;
 }

 $base_arguments["InstanceName"] = $params["InstanceName"];

 if(isset($params["Value"])) $base_arguments["Value"] = $params["Value"];
 if(isset($params["Width"])) $base_arguments["Width"] = $params["Width"];
 if(isset($params["Height"])) $base_arguments["Height"] = $params["Height"];
 if(isset($params["ToolbarSet"])) $base_arguments["ToolbarSet"] = $params["ToolbarSet"];
 if(isset($params["CheckBrowser"])) $base_arguments["CheckBrowser"] = $params["CheckBrowser"];
 if(isset($params["DisplayErrors"])) $base_arguments["DisplayErrors"] = $params["DisplayErrors"];

 // Use all other parameters for the config array (replace if needed)
 $other_arguments = array_diff_assoc($params, $base_arguments);
 $config_arguments = array_merge($config_arguments, $other_arguments);

 $out = ”;

 if($init)
 {
  $out .= ‘<script type=”text/javascript” src=”‘ . $base_arguments["BasePath"] . ‘fckeditor.js”></script>’;
 }

 $out .= “n<script type=”text/javascript”>n”;
 $out .= “var oFCKeditor = new FCKeditor(‘” . $base_arguments["InstanceName"] . “‘);n”;

 foreach($base_arguments as $key => $value)
 {
  if(!is_bool($value))
  {
   // Fix newlines, javascript cannot handle multiple line strings very well.
   $value = ‘”‘ . preg_replace(“/[rn]+/”, ‘” + $0″‘, addslashes($value)) . ‘”‘;
  }
  $out .= “oFCKeditor.$key = $value; “;
 }

 foreach($config_arguments as $key => $value)
 {
  if(!is_bool($value))
  {
   $value = ‘”‘ . preg_replace(“/[rn]+/”, ‘” + $0″‘, addslashes($value)) . ‘”‘;
  }
  $out .= “oFCKeditor.Config["$key"] = $value; “;
 }

 $out .= “noFCKeditor.Create();n”;
 $out .= “</script>n”;

 return $out;
}
?>

使用代码

 代码如下 {fck InstanceName=”body”  BasePath=“../plugins/fckeditor/” Value=$news_info.body Width=”100%” Height=”400″}

可以自定义参数 ToolbarSet-使用的工具栏, BasePath-fck相对于当前脚本的目录,InstanceName-要赋予的$_POST变量名, Value-默认值等

smarty模板的作用|smarty模板中怎么使用fckeditor

http://m.bbyears.com/jiaocheng/36161.html

推荐访问:
相关阅读 猜你喜欢
本类排行 本类最新