KDevelop5/File template specification: Difference between revisions

    From KDE TechBase
    No edit summary
    Line 16: Line 16:


    The variables which are passed to class templates are described in the {{class|TemplateClassGenerator|kdevelop|extragear}} API documentation.
    The variables which are passed to class templates are described in the {{class|TemplateClassGenerator|kdevelop|extragear}} API documentation.
    === Custom options ===
    Templates can expose configuration options to the user prior to the class generation. To do this, add a KConfig XT formatted file into the archive, and specify an <tt>Options</tt> entry in the template description file pointing to it.
    {{Input|1=<nowiki>
    Options=options.kcfg
    </nowiki>}}
    For information about the options file format, see [[Development/Tutorials/Using_KConfig_XT]].

    Revision as of 07:24, 10 July 2012

    Template language

    Class templates use the Grantlee library for rendering templates. It has more features than KMacroExpander, the most important being loops and the ability to expose custom data types from C++ code to templates. The use of Grantlee makes templates more powerful, but also more difficult to write.

    For information regarding Grantlee templates in general, refer to its documentation. Since Grantlee's template language is based on Django's, it might be useful to read the Django template documentation as well.

    File Structure

    Like project templates, class templates are compressed directories, and they too contain a special description file and any number of content files. It is recommended that the description file has a .desktop extension instead of .kdevtemplate, although both are supported.

    Unlike with project templates, not all files from the archive are copied to the output directory. Because Grantlee supports template inheritance and inclusions, class templates may contain helper files that only serve for convenience and produce no actual output. The actual output files have to be specified in the template description.

    Description File Format

    Variables

    The variables which are passed to class templates are described in the Expression error: Unrecognized word "extragear". API documentation.

    Custom options

    Templates can expose configuration options to the user prior to the class generation. To do this, add a KConfig XT formatted file into the archive, and specify an Options entry in the template description file pointing to it.

    Options=options.kcfg
    

    For information about the options file format, see Development/Tutorials/Using_KConfig_XT.