一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

smarty模板中怎么使用fckeditor

时间:2012-11-20 编辑:简简单单 来源:一聚教程网

在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 .= ‘’;
 }

 $out .= “nn”;

 return $out;
}
?>

使用代码

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

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

热门栏目