Blocks are pre-defined page elements which can be used in various places in various ways. They can have parameters to allow them to display something different in each circumstance. As you'll read below, they can appear in layouts, in templates and in editable regions of a page. They can be shared between pages or unique to a page. They can contain any content, including various modules which provide advanced content such as a map, a form or a picture gallery.
Blocks are created by choosing "Blocks" from the "Design" menu. A block can be available only to a specific page template, or it can be available to all page templates. This doesn't dictate that a block necessarily be used, it is just a mechanism to avoid showing a user the option of adding a block to a page which is using a template in which that block would have no purpose. For example, a "Article References" block might be available only on a page created with the "Article" template.
A block description should be added to allow an editor/user to know what the block does when they are choosing from a list of available blocks whilst they're editing a page.
The main part of a block is its "body". The body contains the content which will be displayed when the block is used. This can contain any HTML you wish (the HTML is not sanitised). If complex functionality is required withint the block it should be formatted as an ERB template. For example, you could use a loop:
<% [ "North", "East", "South", "West" ].each do |region| %> <h2><%= region %></h2> <% end %>
One of the most powerful features available in a block is that of a Block Parameter. These allow you to have part of the block be prompted for so that the user provides a value. To define a parameter, use this syntax:
[[field_id:field_type:title]]where "field_id" is a unique identifier for the parameter, "field_type" is one of the following:
line
: A single line of texttext
: Several lines of text, i.e. one or more paragraphsfriendly
: Several lines of text, with friendly formatting (for adding links, bold, italic, etc.)image
: A single line field with an image browserlink
: A single line field with a link browsergallery
: A select showing the names of the defined galleriesmenu
: A select showing the names of the defined menussnippet
: A select showing the names of the defined snippetsform
: A select showing the names of the defined formsParameters are used in the same place they are defined. That is, when the page is shown, the value of the parameter will replace the parameter definition. For example, consider this block body definition:
Hello [[name:line:Contact Name]]!!!When this snippet is placed on a page, the user will be prompted to enter a "Contact Name". If they were to enter "Sally Jones" then when the block is rendered on a page it would look like this:
Hello Sally Jones!!!
For a slightly more advanced example, consider how to add an image in a Block. The parameter part is actually the "src" tag of the HTML <img> tag, so the block body definition would look like this:
<img src="[[image:line:Image Source]]" />or better still, use the parameter type "image" so that the user is offered an image browser to help them fill in the value of the parameter, like this:
<img src="[[image:image:Image Source]]" />Assuming the user entered "/images/picture.jpg" as the image source, the end result of either of this would be:
<img src="/images/picture.jpg" />
There are three ways blocks can be used. These are:
Note, as described above, these can only be used in a Page Template, not in a Layout.
= kit_editable_block(block_instance_id, block_id, { defaults })For example:
= kit_editable_block('special_block_27', 7, {:url=>"http://www.dsc.net", :color=>"red"})
The block_instance_id must be unique within the page the block is to appear (i.e. if you have two of these editable blocks in one template they must each have different instance IDs. The block_id is the identifier for the actual block definition. Defaults is a hash with one entry per default value.
Note, as described above, these can appear in either a Page Template or a Layout.
= kit_block(instance_id)
instance_id is the name of the block instance, which is set at the time the block instance is created. To create a block instance, first choose from the list of blocks, then view the detail of the block concerned and choose Create Instance. Give it a name and set its parameters. You can change the parameters at any time and they will instantly be updated on every page on which this Block Instance appears.