Search code examples
c1-cms

C1 as a store and editor for custom private files


Preface

Our site uses C1 as a CMS for public area (info, help, faq, etc.). Our private area is implemented as a standalone ASP.NET app, so there almost no connection between the CMS and the app.

In the app there are ~50 email templates (HTML+razor), and almost all of them are localized (8 languages).

At the moment those templates are stored as files, and they are under the source control. Consequently, any editing is done by developers.

The goal

We'd like to put those template files under the control of Composite C1 and thereby make them editable by people who manage the content.

The key requirements:

  • The template files must not be accessible by the internet user; the CMS must only show them in the administration console and allow to edit them. It's easy to achieve this by putting the files in e.g. App_Data, so they will be observable in the System perspective, however it's not the best way when considering security, and it doesn't help with the following requirements.
  • It would be great to have the published/unpublished feature applied to these files, just like the pages in the Content perspective.
  • It would be great to use the built-in C1 localization feature, so that at a time only those files are visible, which are in the currently selected language.

The questions

Is there anybody who had experience with putting such private content under the C1 control? In order to meet the requirements, would it make us to store our email templates in the CMS database instead of storing them as files?

UPDATE

In the Data perspective it's possible to create a custom global datatype suitable for storing email templates: it's just necessary to have at least one field "Body" of type String with the xhtml editor assigned to it. This way it's possible to add all the templates into the database, and there are abilities to make them published/unpublished and localized. The application would have to access the templates via the database, what is OK.

The only actual problem is that the xhtml editor should be reconfigured to allow non-strict html with razor. Any advice on that?


Solution

  • So, here is the solution we've ended with.

    1. Create custom global datatype EmailTemplate in the Data perspective.

      Tick the "Has publishing" checkbox in the Settings tab.

      The most important fields are:

      • TemplateID - the string identifier of the email template
      • Body - the template text

      The Body field should be thoroughly configured:

      • Field type: String
      • String maximum length: Unlimited length
      • Advanced config: Widget type: VisualXhtmlEditor
    2. Enable Localization for the newly created datatype (see its context menu).

    3. Edit Form Markup for the newly created datatype (see its context menu).

      Replace the InlineXhtmlEditor element with the following code:

      <TextEditor Label="Template" Help="" MimeType="application/x-cshtml">
          <cms:bind source="Body" />
      </TextEditor>
      

      This way the editor is configured to support the html+razor syntax.

    4. Show the datatype in Content perspective (see its context menu).

      This way the email templates appear in the Website Items of the Content tree.


    How the application can access the published email templates

    In the CMS database the following tables will be created:

        dbo.<datatype_name_with_namespace>_<culture_code>
        dbo.<datatype_name_with_namespace>_Unpublished_<culture_code>
    

    For example

        dbo.Composite_EmailTemplate_en_GB
        dbo.Composite_EmailTemplate_Unpublished_en_GB
        dbo.Composite_EmailTemplate_de_DE
        dbo.Composite_EmailTemplate_Unpublished_de_DE
        ...
    

    Each table has columns that correspond the fields configured for the datatype, e.g. TemplateID and Body.

    I believe now it's clear how to find certain template in certain culture.