Reputation: 20446
I have a basic class that I extend fairly often. I thought it would be nice to add a template of the extension as a choice when creating a new file. I went to Eclipse->Preferences->PHP->Code Style->Code Templates and decided to copy and modify the "Simple php file". So I exported that template and opened it up. It looks like this:
<?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>
I edited the file to look like this:
<?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>
Then I saved it as item.xml and tried to import it. The import threw no errors, but the new template didn't show up in the list. The only thing I can think is that the string I chose for the id attribute is problematic. But I can't find any references on properly authoring a template. Either my google-fu is failing, or I'm trying to do something I'm not supposed to; I don't know.
Ideas?
Upvotes: 2
Views: 3059
Reputation: 2916
The problem you have here is that there is an space in the name of a variable the third line of the template, ${enter description}
and this isn't allowed by eclipse, but those variables won't be considered for autofilling.
Even though, it'll not let you import them, because it's a feature that is no longer supported, as stated in their bugtracker. You could use the current templating system, wich will let you add variables to autofill. To use it, you have to go to PHP > Editor > Templates
. Then, you'd create a new template with wichever name you want, and when you started typing it on a new php file, if you'd select it from the auto-complete.
Upvotes: 4