【发布时间】:2011-04-01 14:45:06
【问题描述】:
我有一个基本类,我经常扩展它。我认为在创建新文件时添加扩展模板作为选择会很好。我去了 Eclipse->Preferences->PHP->Code Style->Code Templates 并决定复制和修改“简单的 php 文件”。所以我导出了那个模板并打开了它。它看起来像这样:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<templates>
<template autoinsert="true" context="php_new_file_context"
deleted="false" description="Simple php file" enabled="true"
id="org.eclipse.php.ui.editor.templates.php.author" name="New simple PHP file">
<?php
${cursor}
?>
</template>
</templates>
我将文件编辑为如下所示:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<templates>
<template autoinsert="true" context="php_new_file_context"
deleted="false" description="PHP Item subclass file" enabled="true"
id="org.eclipse.php.ui.editor.templates.php.itemclass" name="Item subclass file">
<?php
/**
* ${enter description}
* @author: My Name
* @version:
**/
class ${classname} extends Item {
const PKEY='${pkey}'; //name of primary key variable
const TABLE='${table}'; //name of db table
//db table vars
$${pkey};
$${name};
//history vars
public static function who() {
return __CLASS__;
}
}
?>
</template>
</templates>
然后我将它保存为 item.xml 并尝试导入它。导入未引发错误,但新模板未显示在列表中。我唯一能想到的是,我为 id 属性选择的字符串是有问题的。但我找不到任何关于正确创作模板的参考资料。要么我的 google-fu 失败了,要么我正在尝试做一些我不应该做的事情;我不知道。
想法?
【问题讨论】:
标签: xml eclipse templates eclipse-pdt