Skip to content

Resource templates

The resource-template:* commands list, import, export and delete resource templates. The export is the same JSON file as the Export button in the Omeka S admin interface, so templates can move between installations or be kept in version control.

Install the Common module

resource-template:import uses the Common module to match the vocabularies, properties and data types of a template with those of the installation. Install it first:

omeka-s-cli module:download common --install

The other resource-template:* commands work without it. See Modules for more on module:download.

List the resource templates

omeka-s-cli resource-template:list
+----+---------------+-------+---------------+-----------+-------+
| Id | Label         | Class | PropertyCount | ItemCount | Owner |
+----+---------------+-------+---------------+-----------+-------+
| 1  | Base Resource | N/A   | 20            | 0         | N/A   |
+----+---------------+-------+---------------+-----------+-------+

--json and --csv give the same data for scripts:

omeka-s-cli resource-template:list --json | jq -r '.[].label'

Import a resource template

resource-template:import creates a resource template from an exported JSON file (a path or a URL):

omeka-s-cli resource-template:import ~/templates/letter.json
~/templates/letter.json
{
    "o:label": "Letter",
    "o:resource_class": {
        "vocabulary_namespace_uri": "http://purl.org/ontology/bibo/",
        "vocabulary_label": "Bibliographic Ontology",
        "local_name": "Letter",
        "label": "Letter"
    },
    "o:title_property": {
        "vocabulary_namespace_uri": "http://purl.org/dc/terms/",
        "vocabulary_label": "Dublin Core",
        "local_name": "title",
        "label": "Title"
    },
    "o:resource_template_property": [
        {
            "o:alternate_label": null,
            "o:alternate_comment": null,
            "o:is_required": true,
            "o:is_private": false,
            "o:default_lang": null,
            "data_types": [
                {
                    "name": "literal",
                    "label": "Text"
                }
            ],
            "vocabulary_namespace_uri": "http://purl.org/dc/terms/",
            "vocabulary_label": "Dublin Core",
            "local_name": "title",
            "label": "Title"
        },
        {
            "o:alternate_label": "Sender",
            "o:alternate_comment": null,
            "o:is_required": false,
            "o:is_private": false,
            "o:default_lang": null,
            "data_types": [
                {
                    "name": "literal",
                    "label": "Text"
                },
                {
                    "name": "resource:item",
                    "label": "Item"
                }
            ],
            "vocabulary_namespace_uri": "http://purl.org/dc/terms/",
            "vocabulary_label": "Dublin Core",
            "local_name": "creator",
            "label": "Creator"
        },
        {
            "o:alternate_label": "Recipient",
            "o:alternate_comment": null,
            "o:is_required": false,
            "o:is_private": false,
            "o:default_lang": null,
            "data_types": [
                {
                    "name": "literal",
                    "label": "Text"
                },
                {
                    "name": "resource:item",
                    "label": "Item"
                }
            ],
            "vocabulary_namespace_uri": "http://purl.org/ontology/bibo/",
            "vocabulary_label": "Bibliographic Ontology",
            "local_name": "recipient",
            "label": "recipient"
        },
        {
            "o:alternate_label": null,
            "o:alternate_comment": null,
            "o:is_required": false,
            "o:is_private": false,
            "o:default_lang": null,
            "data_types": [
                {
                    "name": "literal",
                    "label": "Text"
                }
            ],
            "vocabulary_namespace_uri": "http://purl.org/dc/terms/",
            "vocabulary_label": "Dublin Core",
            "local_name": "date",
            "label": "Date"
        },
        {
            "o:alternate_label": null,
            "o:alternate_comment": null,
            "o:is_required": false,
            "o:is_private": false,
            "o:default_lang": null,
            "data_types": [
                {
                    "name": "literal",
                    "label": "Text"
                },
                {
                    "name": "uri",
                    "label": "URI"
                }
            ],
            "vocabulary_namespace_uri": "http://purl.org/dc/terms/",
            "vocabulary_label": "Dublin Core",
            "local_name": "rights",
            "label": "Rights"
        }
    ]
}

The template gets the label in the file, unless you give another one with --label. That way, one file can create several templates:

omeka-s-cli resource-template:import ~/templates/letter.json --label "Letter (incoming)"

Labels are unique: if a template with the label already exists, the command changes nothing, prints a notice and exits with code 0.

Update a resource template

Add --update to replace the template that has the same label with the content of the file:

omeka-s-cli resource-template:import ~/templates/letter.json --update

To update a template with another label, give its id or label after the file. The template is updated and gets the label of the file, or the one from --label:

omeka-s-cli resource-template:import ~/templates/letter.json "Letter (incoming)" --label "Incoming letter"

Warning

When you update a template by id or label, the label in the file replaces the template's label. If another template already has that label, the update fails. Pass --label with the template's current label to keep it.

Handle missing dependencies

A template refers to its properties and resource class by vocabulary namespace URI and local name, and to its data types by name. Before importing, the command checks that all of them exist in the installation. If something is missing, it lists what and imports nothing:

if ! omeka-s-cli resource-template:import ~/templates/archive-letter.json; then
    echo "Import the missing vocabulary first." >&2
fi
The resource template has missing dependencies:
- Vocabularies: https://example.org/archive#
Could not import the resource template due to missing dependencies.

Missing data types usually come from a module that is not installed, such as Numeric Data Types (numeric:timestamp) or Value Suggest (valuesuggest:...). Custom vocabulary data types are matched by the label of the custom vocabulary (see Custom vocabularies).

The best fix is to install what is missing and import again. Here the template uses the vocabulary from the Vocabularies page:

omeka-s-cli vocabulary:import --config ~/vocabularies/archive.json
omeka-s-cli resource-template:import ~/templates/archive-letter.json

--ignore-deps imports the template anyway, without the resource class, properties and data types that do not exist:

omeka-s-cli resource-template:import ~/templates/archive-letter.json --ignore-deps --label "Archive letter (partial)"

Here the template keeps only dcterms:title and dcterms:date; the class and the two properties from the missing vocabulary are left out.

Export a resource template

resource-template:export takes the id or the label of a template. Without a file name it prints the JSON:

omeka-s-cli resource-template:export "Letter" | jq -r '."o:resource_template_property"[].label'

With a file name it writes the JSON to that file, overwriting it if it exists:

mkdir -p ~/backup
omeka-s-cli resource-template:export "Letter" ~/backup/letter.json

To back up all templates, combine it with resource-template:list:

omeka-s-cli resource-template:list --json | jq -r '.[].id' | while read -r id; do
    omeka-s-cli resource-template:export "$id" ~/backup/resource-template-"$id".json
done

Delete a resource template

resource-template:delete takes the id or the label of a template. With --ignore-not-found, a template that does not exist is not an error:

omeka-s-cli resource-template:delete "Incoming letter"
omeka-s-cli resource-template:delete "Letter (draft)" --ignore-not-found

A template that is used by items is not deleted unless you add --force. The items keep their values; they no longer have a resource template.

Reference

All commands also accept the global options.

resource-template:list

List available resource templates

omeka-s-cli resource-template:list [options]
Option Description Default
-j, --json Output json
-c, --csv Output csv

resource-template:import

Import a resource template

omeka-s-cli resource-template:import [options] <source> [identifier]
Argument Description Default
<source> File or URL to import from
[identifier] Resource template ID or label (required for update)
Option Description Default
-l, --label <value> Set or override the resource template label
--update Update existing resource template
--ignore-deps Ignore missing dependencies (vocabularies, properties, classes, data types)

resource-template:export

Export a resource template

omeka-s-cli resource-template:export <identifier> [filename]
Argument Description Default
<identifier> Resource template ID or label
[filename] Export to file

resource-template:delete

Delete a resource template

omeka-s-cli resource-template:delete [options] <identifier>
Argument Description Default
<identifier> Resource template ID or label
Option Description Default
-f, --force Force delete
--ignore-not-found Do nothing if the resource template does not exist (default: throw an error)