fckeditortemplates.xml模板内容是这样的<?xml version="1.0" encoding="utf-8" ?><Templates imagesBasePath="fck_template/images/">
<Template title="Image and Title" image="template1.gif">
<Description>One main image with a title and text that surround the image.</Description>
<Html>
html代码略.... </Html>
</Template>
<Template title="Strange Template" image="template2.gif">
<Description>A template that defines two colums, each one with a title, and some text.</Description>
<Html>
html代码略.... </Html>
</Template>
<Template title="Text and Table" image="template3.gif">
<Description>A title with some text and a table.</Description>
<Html>
html代码略.... </Html>
</Template>
</Templates>
从以上代码可以看到,每一对<teplate> </templates>是一个节点,里面是html代码即模板,上面看到有三对<teplate> </templates>,即装了三个模板
要怎样调用模板而不是在编辑器里面手动选择呢,我试过把html源码放在数据库里面,但是放不下,太大了。也试过加html连接到模板,但是显示在编辑器里面却不能编辑表格了.....唯一的办法就是放在xml文件里面,让编辑器解析出来,表格可以编辑...
<Template title="Image and Title" image="template1.gif">
<Description>One main image with a title and text that surround the image.</Description>
<Html>
html代码略.... </Html>
</Template>
<Template title="Strange Template" image="template2.gif">
<Description>A template that defines two colums, each one with a title, and some text.</Description>
<Html>
html代码略.... </Html>
</Template>
<Template title="Text and Table" image="template3.gif">
<Description>A title with some text and a table.</Description>
<Html>
html代码略.... </Html>
</Template>
</Templates>
从以上代码可以看到,每一对<teplate> </templates>是一个节点,里面是html代码即模板,上面看到有三对<teplate> </templates>,即装了三个模板
要怎样调用模板而不是在编辑器里面手动选择呢,我试过把html源码放在数据库里面,但是放不下,太大了。也试过加html连接到模板,但是显示在编辑器里面却不能编辑表格了.....唯一的办法就是放在xml文件里面,让编辑器解析出来,表格可以编辑...
$oFCKeditor = new FCKeditor("try4") ;
$oFCKeditor->BasePath = 'fckeditor/' ;
$oFCKeditor->ToolbarSet = 'Default' ;
$oFCKeditor->Value = isset($content)?$content:"" ;
$oFCKeditor->InstanceName = 'content' ;
$oFCKeditor->Width = '100%' ;
$oFCKeditor->Height = '450' ;
$oFCKeditor->Create() ;
?>
我用的是jsp...itian大哥,对php不是很懂,我对上面的代码理解是在PHP环境下初始化一个fckeditor编辑器.
模板的源码要到fckeditortemplates.xml文件里面(这个文件在editor文件下)取,我们每次选择模板都会出发一个事件
就是找不到触发模板时间的函数在哪里...
不知道谁对这个有研究....
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>FCKeditor - Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex, nofollow" />
<link href="../_samples/sample.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="fckeditor.js"></script>
</head>
<body>
<h1>
FCKeditor - JavaScript - Sample 1
</h1>
<div>
This sample displays a normal HTML form with an FCKeditor with full features enabled.
</div>
<hr />
<form action="sampleposteddata.asp" method="post" target="_blank">
<script type="text/javascript">
//===========================================================
//Index:要加载的模板的索引号,从0开始
//url:模板xml的路径,相对当前页面
function ShowBo__LoadTemplates(Index,url)//使用ajax加载xml模板文件,防止google浏览器的不支持浏览xml加载的方法从而不能在google浏览器里初始化
{
url+="?ts="+new Date().toString();
var o;
if(window.XMLHttpRequest)o=new XMLHttpRequest();
else if(window.ActiveXObject)o=new ActiveXObject("microsoft.xmlhttp");
else{ alert("浏览器不支持当前流行的ajax!");return "";}
if(o){
o.open('get',url,false);//同步
o.send(null)
var dom=o.responseXML;
var tmps=dom.getElementsByTagName("Html");//获取模板html
if(tmps.length==0)return "";//没有模板或者路径出错时则返回空
if(Index>=tmps.length)Index=0;//索引号大于模板数量则默认第一个模板
return tmps[Index].firstChild.nodeValue;
}
}
//===========================================================
var tmpHtml=ShowBo__LoadTemplates(1,'fcktemplates.xml');//加载模板1
</script>
<script type="text/javascript">
var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('_samples')) ;var oFCKeditor = new FCKeditor( 'FCKeditor1' ) ;
oFCKeditor.BasePath = sBasePath ;
oFCKeditor.Height = 300 ;
oFCKeditor.Value = tmpHtml;//设置模板
oFCKeditor.Create() ;
</script>
<br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
用js来加载就行了,加载函数看ShowBo__LoadTemplates的说明,然后设置oFCKeditor.Value就可以了
|
|--fckeditor(编辑器的文件夹)
| |
| |--test.html(一个测试页面,使用加载模板函数的,代码在最后贴出)
| |--fcktemplates.xml(fck的模板配置文件)
| |__......其他的文件和文件夹,fck默认有的
|
|--你的其他文件和文件夹
|
|__test1.html(另一个测试页面)
在fckeditor目录下的test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>FCKeditor - Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex, nofollow" />
<link href="_samples/sample.css" rel="stylesheet" type="text/css" /><!--------注意路径------------>
<script type="text/javascript" src="fckeditor.js"></script><!--------注意路径------------>
</head>
<body>
<h1>
FCKeditor - JavaScript - Sample 1
</h1>
<div>
This sample displays a normal HTML form with an FCKeditor with full features enabled.
</div>
<hr />
<form action="sampleposteddata.asp" method="post" target="_blank">
<script type="text/javascript">
function getHTML(o){
var r="";
for(var i=0;i<o.childNodes.length;i++)r+=o.childNodes[i].nodeValue;
return r;
}
//Index:要加载的模板的索引号,从0开始
//url:模板xml的路径,相对当前页面
function ShowBo__LoadTemplates(Index,url)//使用ajax加载xml模板文件,防止google浏览器不支持当前通用的xml加载的方法从而不能在google浏览器里初始化
{
url+="?ts="+new Date().toString();
var o;
if(window.XMLHttpRequest)o=new XMLHttpRequest();
else if(window.ActiveXObject)o=new ActiveXObject("microsoft.xmlhttp");
else{ alert("浏览器不支持当前流行的ajax!");return "";}
if(o){
o.open('get',url,false);//同步
o.send(null)
var dom=o.responseXML;
var tmps=dom.getElementsByTagName("Html");//获取模板html
if(tmps.length==0)return "";//没有模板或者路径出错时则返回空
if(Index>=tmps.length)Index=0;//索引号大于模板数量则默认第一个模板
return document.all?tmps[Index].firstChild.nodeValue:getHTML(tmps[Index]);
}
}var tmpHtml=ShowBo__LoadTemplates(1,'fcktemplates.xml');//加载模板1====================和配置文件处在同一个目录
</script>
<script type="text/javascript">
var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('_samples')) ;var oFCKeditor = new FCKeditor( 'FCKeditor1' ) ;
oFCKeditor.BasePath = sBasePath ;
oFCKeditor.Height = 300 ;
oFCKeditor.Value = tmpHtml;//设置模板
oFCKeditor.Create() ;
</script>
<br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
xxxx下的test1.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>FCKeditor - Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="robots" content="noindex, nofollow" />
<link href="fckeditor/_samples/sample.css" rel="stylesheet" type="text/css" /><!--------注意路径------------>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script><!--------注意路径------------>
</head>
<body>
<h1>
FCKeditor - JavaScript - Sample 1
</h1>
<div>
This sample displays a normal HTML form with an FCKeditor with full features enabled.
</div>
<hr />
<form action="sampleposteddata.asp" method="post" target="_blank">
<script type="text/javascript">
function getHTML(o){
var r="";
for(var i=0;i<o.childNodes.length;i++)r+=o.childNodes[i].nodeValue;
return r;
}
//Index:要加载的模板的索引号,从0开始
//url:模板xml的路径,相对当前页面
function ShowBo__LoadTemplates(Index,url)//使用ajax加载xml模板文件,防止google浏览器不支持当前通用的xml加载的方法从而不能在google浏览器里初始化
{
url+="?ts="+new Date().toString();
var o;
if(window.XMLHttpRequest)o=new XMLHttpRequest();
else if(window.ActiveXObject)o=new ActiveXObject("microsoft.xmlhttp");
else{ alert("浏览器不支持当前流行的ajax!");return "";}
if(o){
o.open('get',url,false);//同步
o.send(null)
var dom=o.responseXML;
var tmps=dom.getElementsByTagName("Html");//获取模板html
if(tmps.length==0)return "";//没有模板或者路径出错时则返回空
if(Index>=tmps.length)Index=0;//索引号大于模板数量则默认第一个模板 return document.all?tmps[Index].firstChild.nodeValue:getHTML(tmps[Index]);
}}var tmpHtml=ShowBo__LoadTemplates(1,'fckeditor/fcktemplates.xml');//加载模板1=====================================</script>
<script type="text/javascript">
var sBasePath = "fckeditor/" ;//===========================注意设置这里的目录,是你当前目录相对与fckeditor目录的相对路径,最后一个/不能少
var oFCKeditor = new FCKeditor( 'FCKeditor1' ) ;
oFCKeditor.BasePath = sBasePath ;
oFCKeditor.Height = 300 ;
oFCKeditor.Value = tmpHtml;//设置模板
oFCKeditor.Create() ;
</script>
<br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
|--src(包)
|--webroot
| | |
| | fckeditor(编辑器的文件夹,fcktemplates.xml文件就在下面)
| |
| 我的jsp页面
| 恩,我的目录结构和你的test1是相同的
这是初始化编辑器的代码 //创建编辑器
var oFCKeditor = new FCKeditor('content');
//制定编辑器路径:工程名加编辑器主文件夹
oFCKeditor.BasePath = "/fck/fckeditor/"; //===============原来按你test.html设置路径,所以初始化不了===============
oFCKeditor.Width="60%";
oFCKeditor.Height="750";
//设置编辑器初始值
oFCKeditor.Value="xxxxx"; // =========试过"<%Java代码%>"结果打印的就是""里面的东西,我以为这里只能用字符串。=======
//工具集设定
//默认全部工具
oFCKeditor.ToolbarSet="Default";
// 自定义工具集
// oFCKeditor.ToolbarSet="editor";
oFCKeditor.Create();
//配置路径
oFCKeditor.Config["CustomConfigurationPath"]="/fck/fckedito/fckconfig.js"; 谢谢色波,你贴上的代码怎么和编辑器里面的颜色一样,咋弄的