You are here

Cel

Submitted by Peter on Sat, 2012-11-03 13:40

Cel approaches templating the way a cel is used in animation.

Cel connects direct to Twig through module Cel Twig.

Templating

Templating is used throughout applications, including content management, in Web sites, and email generation. You see default values for things everywhere. The defaults and templates are often buried in files you have to download, edit, then upload. A good templating system would shift all that file editing to a simple easy online edit.

The files are then used as the starting point to create something else. The template might be the standard text for an email you send out each week. The template might contain tokens to substitute current information so you do not have to edit the template each week. The template editing should be available direct to whoever creates the content of the template and should not have to go through a Web developer.

As an example of using tokens, Drupal has a token system to feed site information into your template. The Token ex module helps you add other tokens for your site telephone number, standard colours, your star sign, whatever. You can change information without editing the template file. Adding a token into a template should be no more restrictive than addting the token to the system.

There is also a wide range of template programming languages. These started in the 1980s with templating languages added on to CICS. People were already processing templates through conventional programming languages and started writing languages specific to templating. Some language software products interpreted the template language while others compiled. Compiled templates produce the best performance in high speed transaction systems like CICS and Web sites, while interpreted systems are easier for the low volume applications, including your once per week newsletter email.

Templating in Drupal

There are a lot of templating systems in Drupal. Each module builds a new one. Is there a way to handle the template editing and storage once without continually reinventing it? Yes, Cel does that. You install Cel once, Cel uses all the good features already built into Drupal, and your modules use Cel.

Cel replaces those difficult to access template files with Drupal content. Yes, that nice content you can edit online. That nice content you can control by user or role. No more fighting with file systems.

Cel places the template in a separate cel so the body of the content can be used for your documentation. Yes, documentation.

You can use filters to control the template content and the filter choice for the cel is independent of the choice for the rest of the content. All the controls for display and access are already built into Drupal.

It might take a while for module developers switch to Cel. Talk to them about the benefits.

Cel is available inside and outside Drupal with the Drupal version using Drupal nodes for storage. The Drupal version is in a drupal.org sandbox until approved for publication as a module. The approval process is growing longer faster than applications are approved.

Templating with Twig

Drupal 8 will use Twig as a template language. Twig is available now in Drupal 7 through the Twig7 module. The Cel Twig module connects Twig to Cel so you can use cels in Twig.

All the features of Twig are available. Every cel is a template to Twig. You can include cels within cels using Twig code instead of tokens.

When you use the Cel Twig functions, the templates go through Twig first then through the Drupal token system to let you use Twig for content construction and tokens for common site information.

Who?

Cel is for everyone who was not born speaking PHP. The current generation of kids can only use touch screens, not keyboards, and none of them will edit system files to change templates. Cel is designed to be used by the apps used by the current generation.

What?

What you need is the Cel module installed in your Drupal based Web site. You then create a cel and tell your developers the name of your cel. They create a one off enhancement to add Cel and the name of your cel into their software. The instant Cel is in their app, you need only to copy and past the cel id for the cel you need.

When?

You can create templates in cels now. The software using the templates will need a slight modification to look for cels as an addition to, or a replacement for, current templates. Modules using the token system can already access cels.

Where?

Your template goes straight in through the Drupal create content link. Select the content type named Cel and start creating.

The template cel will be used by a module or application. The using code simply chooses a cel instead of a file. The rest is the same.

Cel already includes an option to use cels as blocks. See Cel blocks.

Why?

Templates are used everywhere and are rarely created by the programmers building the Web site. Templates start in your word processing document or layout software the same as all your content. You should be able to cut and paste the template into Drupal exactly the same way you paste content into Drupal.

Bypass the old system of emailing it to the IT manager who then schedules a programmer to look at it and ask questions. Eventually the programmer might edit the template into a template file which might be uploaded during the next window of updates for your production site, provided none of the higher priority changes create problems.

How?

Get Cel from the sandbox at drupal.org/sandbox/peter/1509964 or from cel.zip. I would provide a more efficient 7-Zip version but this Linux box does not have 7-Zip.

Cel is already in use across many sites and applications in various forms. The version here, and in the sandbox, has a few advantages.

  • Nice selection of common features from the other versions.
  • Actively maintained.
  • Uses Drupal features where available.
  • Is compatible with Token ex, Token if, and all templating systems.
  • BSD and MIT licensed versions available.

Sandbox

Sandbox is the drupal.org name for an entry on the site that is in their version control system but not in their official download section. The code ia in the sandbox at drupal.org because some people prefer code from drupal.org. I can add downloads here for anyone wanting to avoid Git.

Code format

The code is converted to the Drupal coding format. This is not really an advantage when you want to read code. The main reason for the conversion is to make it compatible with drupal.org and the automatic download of updates from drupal.org that might be in Drupal 8. We may be able to upgrade the code format a little bit if Drupal adopts PSR-0 or PSR-1.

Coder is one of the programs used to check code compliance with the Drupal stndard. It checks only formatting, not anything really important. It does classify clear easy to read code as an error but it is nothing comapredto PAReview. Coder enforcesrules that might be a good idea purly for consistency. PAReview is best described as theugly stick.

PAReview might do some nice things for raw code. PAReview does nothing for code that is already modified for Coder. Some of the things reported by PAReview are wrong. The rest of the messages appear to be all about enforcing bad codeformatting standards.

PAReview enforces rules that are the opposite of semantic. Almostfrom day one of the Web, the battle started to make things meaningful instead of junk. Your data should be semantic. Not in PAReview. PAReview is enforcing stupid rules implying structure or meading from the way text is decorated.

Class names are just the start. Class names, but not any other name in the code, has to have a capital letter at the start. Do they want us tomake the letter bold or in a different font, as was done in the 13th century? Fortunately no.

Function names get a different treatment. Most functions are allowed in clear neat text without capital letters but functions inside classes have to follow a completely different rule. For those functions, you cannot use the underscore to separate components of thename for readability. Instead you have to squash all the components rightupagainsteachother. Aftermakingeverythingalmostunreadable, you have to decorate the text with capital letters to indicate the start of the terms all squashed RightUpAgainstEachOther.

This sort of stupidity is all over the programming world and everyone does it slightly different. People create standards a, b, c,d, etc. The next group start by saying they will adopt the standard then they make up a new standard by patching together bits of the many exisitng standards.

Oh, one other thing. You are not allowed to use RightUpAgainstEachOther, you have to change it to rightUpAgainstEachOther because that is an even harder standard to use.