How to use FCKeditor in Smarty templates

Source: Internet
Author: User
Tags foreach

Call FCKeditor file in Smarty

The code is as follows Copy Code

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 waiting for You");
$smarty->assign (' FCKeditor ', $FCKeditor);
$smarty->display (' Template.tpl ');

However, the use of this method in the editing of data when the FCKeditor can not pass the value, but generated a null editor, so can only change one way:

  code is as follows copy code

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 waiting for You");
$smartyl->assign_by_ref ("FCKeditor", $editor);
$smarty->display (' Template.tpl ');

Call

The code is as follows Copy Code

<title>example of Smarty Use fckeditor</title>

<body>
<P>Example</p>
<p>title:<{$Title}></p>
<p></p>
<p>content:</p>
<p><{$FCKeditor}></p>
</body>

Example 2

Here I use the Smarty plug-in mechanism, can be more convenient in Smarty integration FCKeditor, in Smarty plugin directory to create new files function.fck.php

The contents are as follows

The code is as follows Copy Code

<?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 '))
{

This sets the default FCK directory, relative to the directory of the program to use 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.
$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;
}
?>

Using code

The code is as follows Copy Code
{FCK instancename= "body" basepath= ". /plugins/fckeditor/"value= $news _info.body width=" 100% "height=" 400″}

You can customize the toolbar used by the parameter toolbarset-, BASEPATH-FCK relative to the current script directory, instancename-to give $_post variable name, value-default value, etc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.