# orion.core.contenttype

The content type service tells Orion about a new kind of file. The content types contributed to this service don't have any direct effect on the Orion UI, but they can be referred to by other services that need to associate themselves with a particular kind of file. For an example, see orion.navigate.openWith.

The Orion client UI defines a bunch of content types by default, including JavaScript, CSS, HTML, Markdown, and several others. See `webEditingPlugin.js` in the client UI code for a full list. (If you are contributing tools that deal with one of Orion's predefined content types, you must use the same content type ID rather than define your own, as file extensions can be registered by only a single content type.)

## Service attributes

contentTypes
  `ContentType[]`. An array of one or more content types to register. Each element of the array defines a new content type.

### The ContentType object

A ContentType object has the following shape:

id
  `String` The unique identifier of the content type. This is a simple hierarchical name and should start with a category like "text" or "image".
name
  `String` The user-readable name of the content type.
extension
  `String[]` Optional. Array of file extensions characterizing this content type. (Extensions are given without the leading "." character). Note that extensions are unique: if two content types both register against the same extension, one content type will be chosen arbitrarily over the other.
filename
  `String[]` Optional. Array of filenames characterizing this content type. Use this when a type does not have a characteristic file extension, but rather a filename. (For example, "Makefile", "README", "passwd").
extends
  `String` Optional. If this content type is a subtype of another, this gives the parent content type's ID.
image
  `String` Optional. URL of an image to display beside files of this type (for example, in the Orion navigator).
imageClass
  `String` Optional. CSS class name for an image to display beside files of this type (for example, in the Orion navigator). Providing a class name allows a variety of CSS techniques to be used to generate an icon: for example, sprites, web fonts, etc. Multiple class names (separated by a space) can be provided within the imageClass string. The imageClass supersedes image if both are provided.

## Service methods

None. This service is purely declarative.

## Example

This example code contributes contributes a new content type for Perl files. A Perl file extends from `"text/plain"` and has the extension `.pl`.

    provider.registerServiceProvider("orion.core.contenttype", {}, {
        contentTypes: [
            {
                id: "application/perl",
                name: "Perl",
                extension: ["pl"],
                "extends": "text/plain"
            }
        ]});
    provider.connect();

The example code below contributes a new content type for Maven build files. A Maven build file is a special kind of XML file that always has the name "pom.xml".

    provider.registerServiceProvider("orion.core.contenttype", {}, {
        contentTypes: [
            {
                id: "text/x-maven-pom",
                name: "Maven build file",
                filename: ["pom.xml"],
                "extends": "application/xml",
                imageClass: "orion-maven-sprite"
            }
        ]});
    provider.connect();

Category:Orion