Skip to content

2.2. Template variables

Rauli Rajande edited this page Oct 11, 2019 · 4 revisions
  1. Install BCCMS and follow the Quickstart to set up your module and first panel template

  2. For variables create a folder "definitions" under your module folder.

  3. Create definition file for the panel. This has to be json file with the same name as panel. Eg c://xampp/htdocs/myproject/modules/myproject/definitions/myfirst.json

  4. Let's add a text variable to the template, so you can say various greetings to the different things. For this the file should contain:

   {
       "version":"2",
       "item":[ 
           {
               "type":"text",
               "name":"greeting",
               "label":"Greeting",
               "default":"Hello"
           },
           {
               "type":"text",
               "name":"thing",
               "label":"Thing",
               "default":"World"
           }
       ]
   }

version - definition file format (has to be 2) item - array of fields on template type - field type text (check "CMS input types" for options) name - variable name (lowercase, numbers-letters only, starts with a letter) label - label for variable what you want to show in CMS admin side default - default value for variable

  1. Add variables to template. Edit panel template file c://xampp/htdocs/myproject/modules/myproject/templates/myfirst.tpl.php

Make this contain this:

    <?= $greeting ?> <?= $thing ?>!

<?= and ?> are markup for PHP templating subset, which print out the variable.

As you see, the variables defined in json file, will appear here as PHP variables.

  1. Go to CMS and Pages -> Homepage -> Myfirst (the panel you added in Quickstart, appears in the right column)
  • Modify the Greeting and the Thing fields.
  • Click Save
  1. Check your website frontend at http://localhost/myproject/

  2. Add another panel of the same type to the page in the CMS with different content.

  3. Try to rearrange panels by drag-and-drop in the CMS page edit.