Skip to content

Instantly share code, notes, and snippets.

@matheusgnreis
Last active September 1, 2021 14:42
Show Gist options
  • Save matheusgnreis/27b4c5eda995a13f663c824e91cc790c to your computer and use it in GitHub Desktop.
Save matheusgnreis/27b4c5eda995a13f663c824e91cc790c to your computer and use it in GitHub Desktop.
Creating new functionality to E-Com Plus CMS

First is adding a functionality in to an existence file. Go to a file that you gonna edit, just like footer.json. Add your propertie or array or object, just like:

  "stores": {
    "list": [
      {
        "title": "Title",
        "text": "Description"
      },
      {
        "title": "Title",
        "text": "Description"
      }
    ]
  }

Then, treat this part of json in your code. In this case, will be in footer.ejs, just like:

<% footer.stores.list.forEach(({ title, text }) => { %>
              <div class="col">
                <strong><%- title %></strong>
                <p><%- text %></p>
              </div>                                  
<% }) %>

If you do this, your code is already working. But, for your user, will be horrible. Because every time he needs to edit it, he will be changing JSON. Our client, do not know how to edit JSON in most of cases.

So we have to insert one more configuration informing some properties with his type respectively, the system will know and render the exact input for that field.

Examples:

  1. Your client need to insert a title or a link or a text: "widget": "string"

  2. Your client need to insert an image: "widget": "image"

  3. Your client need to insert an html or css or js: "widget": "code", "default_language": "html"

  4. Your client need to insert a number of seconds to autoplay or a number of elements of products on collection: "widget": "number"

If you have one or more fields, your widget will be a list or an object or can be both

An example of a list is to receive an array of elements with link, image and target.

An example of object is to receive additional or more than one propertie, just like insert a code. We have additional propertie "default_language": "html".

An example with both, we can see below.

You just need to add this configuration on path /template/public/admin/config.json with propertie "collections". To do that, we have to pass through all the same path of footer and add a new field with the properties that we use on footer.json, just like:

  "collections": [
    {
      "label" : "Moara",
      "name": "moara",
      "files": [
    {
      "label": "Layout",
      "name": "layout",
      "delete": false,
      "description": "Layout base todas as páginas",
      "files": [
        {},
        {},
        {
          "file": "content/footer.json",
          "label": "Rodapé",
          "name": "footer",
          "fields": [
            {
                    "label": "Lojas",
                    "name": "stores",
                    "widget": "object",
                    "fields": [
                      {
                      "label": "Listas de lojas",
                      "name": "list",
                      "widget": "list",
                      "fields": [
                        {
                            "label": "Nome da loja",
                            "name": "title",
                            "widget": "string"
                        },
                        {
                            "label": "Texto da loja",
                            "name": "text",
                            "widget": "string"
                        }
                      ]
                    }
                ]
            }
          ]
        }
      ]
    }
  ]

To test if configuration goes well, you can run locally then go to /admin/ and saw console log. If its okay, will appear the new configuration at the existance collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment