Install content using the Content Interchange Format (CIF)

When installing packages, we often need to create single pages, user attributes, jobs and more. You can do that programmatically using the Concrete CMS API, but it's ways more easy to do that using XML files in Concrete Interchange Format. That's what Concrete does in the install procedure.

Add these lines of code to the controller.php file of your package:

    /*
     * Method called when the package is installed.
     */
    public function install()
    {
        $pkg = parent::install();
        $this->installXml();
        return $pkg;
    }

    /*
     * Method called when an installed package is upgraded to a newer version.
     */
    public function upgrade()
    {
        parent::upgrade();
        $this->installXml();
    }

    /**
     * Install/update data from install XML file.
     */
    private function installXml()
    {
        // install.xml lives in the root of the package.
        $this->installContentFile('install.xml');
    }

The concrete5-cif XML file must start with

<?xml version="1.0"?>
<concrete5-cif version="1.0">

and end with

</concrete5-cif>

Between these line, you have to write the XML definition of what you want to be installed. You can see how to declare typical Concrete structures within the xml files found in concrete/config/install/. Additionally, the Exporter package within the Concrete Migration Tool automatically generates this XML from an existing Concrete site. Simply create the items you want, export them as XML, and include the XML in your package.

Examples