Open source cms for mobile and desktop websites

Element plugin example: Json configuration

pure json configuration example for a page element including new object type, data model, form definition and template

Scaffold download:

The module has to be in the current python path to be added to your website.

website.modules.append("nive_tmpl_element_json:configuration.json")

configuration.json

The file configuration.json defines everything needed to set up the element.

{
    "type": "nive.definitions.ObjectConf",
    "id": "article",
    "name": "Article",
    "dbparam": "article",
    "context": "nive_cms.baseobjects.PageElementBase",
    "template": "nive_tmpl_element_json:article.pt",
    "selectTag": 20,
    "description": "",

   "data": [
       { "type": "nive.FieldConf",
         "id": "textblock", "datatype": "htext", "size": 10000,
         "default": "", "fulltext": 1, "name": "Text", "description": ""},
       { "type": "nive.FieldConf",
         "id": "image", "datatype": "file", "size": 0,
         "default": "", "name": "Imagefile", "description": ""},
       { "type": "nive.FieldConf",
         "id": "link", "datatype": "url", "size": 255,
         "default": "", "name": "Link", "description": ""}
   ],

   "forms": {"create": {"fields": ["title", "textblock", "image"]},
             "edit":   {"fields": ["title", "textblock", "image"]}}
}

article.pt

The page template article.pt is used to render the contents on the web page.

<div class="pageelement peArticle" id="nive-element${context.GetID()}"
     tal:define="link view.ResolveLink(context.data.link)">

<div class="teaser">
<img tal:condition="context.files.get('image')"
          tal:attributes="src view.FileUrl('image', context);
                          title context.GetTitle()" />
<div class="itext">
<h3 tal:content="structure context.GetTitle()"/>
<p tal:condition="context.data.textblock"
   tal:replace="structure context.data.textblock"></p>
<a tal:condition="link" tal:attributes="href link">&gt; more</a>
</div>
</div>

</div>
© 2013 Nive GmbH