PHPCow Template Language – Pagination Module

Posted On: October 6, 2008

Continuing CTL topic, I want to introduce new pagination module developed for new template engine. Pagination is a must feature for any content related system. We tried to develop universal module which could be integrated with any other module that requires pagination. Introduced module is highly customizable that gives template authors unlimited capabilities to feet pagination to desired needs.

Simplest usage of the pagination module is shown below:

{mod:cow:pagination uri_pattern="/blog/posts/page/{page_number}" record_count="50" limit="3"}
    {var:pagination.links}
{/mod:cow:pagination}

Shown snippet of code will generate pagination shown on the pictures:

Shown example uses three attributes 1) uri_pattern - Defines URI to be used for paginated results. It is possible to use any URI pattern but there is one simple requirement that URI must contain "{page_number}" special variable. Pagination module will replace this variable with apropriate page number; 2) record-count - that defines total count of particular type of content (e.g. blog posts or news); 3) limit - defines how many items must be shown per page;

There are much more attributes that could be supplied to the module, these attributes give endless customization options to template authors. For example it is possible to change labels for next, previous, first, and last links or change number of adjacent pages.

Supported attributes are listed below:

//URI to be used for paginated results
uri_pattern="{var:env.context}/posts/page/{page_number}"

//Previous/Next links to be shown, defaults to "false"
prev_next="true" 

//First/Last links to be shown, defaults to "true"
first_last="false"

//label for "Previous" link
prev_label="« Previous"

//label for "Next" link
next_label="Next »" 

//label for "First" link
first_label="First"

//label for "Last" link 
last_label="Last"

//total number of records (e.g. blog posts or news)
record_count="50"

//how many results must be shown on each page
limit="3"

//number of adjacent pages, defaults to "3"
adjacent="2"

PHPCow Template Language – Modules

Posted On: July 19, 2008

Previously I briefly overviewed CTL (see this post). Now I want to introduce another most powerful feature of CTL. This is CTL Module tag.

Think about CTL Module tag as a custom tag. This is a simple tag like construct that allows to integrate new functionality into CTL without harming the core and it requires ZERO configuration. To install module you only need to create correct folder structure.

Module tag looks like something similar:

{mod:cow:tagcloud}
    //rest of content here
{/mod:cow:tagcloud}

Module tags have simple structure. As with other structures it starts and ends with curly braces, followed by “mod:” prefix, followed by “package:” prefix and finally actual module name. Think about package as a simple folder, for the shown example package(folder) name is “cow” and the module name is “tagcloud”.

This is real module which is used in this blog(see right sidebar). We developed this simple but useful module to arrange categories like tag cloud.

As general HTML tags, module tags support attributes. Attribute names are module parameter names and attribute values are module parameter values. See example below:

{mod:cow:comments limit="5" order="desc"}
    <h3>Recent Comment</h3>
    <ul class="tag-cloud">
    {mod:iterator}
        <li>{var:comment.member.name}: {var:comment.title}</li>
    {/mod:iterator}
    </ul>
{/mod:cow:comments}

Shown snippet of code will generate list of recent comments, something like you see on the right sidebar.

In this example we used two attributes, “limit” and “order”. We told module to select five latest comments and order them in descendant order. But, in the example we used one more tag which is a part of module tag specification. This is “mod:iterator” tag. This very useful tag is used to iterate result returned by module, instead of using boring “foreach” structure we used module iterator to generate list of comments.

What we need to develop CTL modules? and is it necessary to dive into PHPCow core API details?

First of all, only thing you need is to extend one base module class. Secondly just begin programming as you do it usually, nothing from PHPCow is necessary except knowing database structure if you are going to enhance PHPCow. In other words you have absolute freedom in you module development.

New PHPCow Template Language(CTL)

Posted On: July 19, 2008

It's not secret that PHPCow doesn't have powerful Template Language. All it has is a template processor that supports predefined set of macros. This of course is huge disadvantage because person who builds templates doesn't have enough flexibility in template customization. Various types of blocks introduced in PHPCow are really powerful and flexible building components, but that is not enough.

For version 3.0, we designed and developed completely new template engine with powerful template language, we called it CTL.

CTL is easy to use and flexible language that gives you enormous power to build highly customized templates.

Think about CTL as Smarty for PHP but with few differences: CTL is not programming language; it is easier to use than Smarty; It doesn't require to compile templates to PHP files and finally it is extensible, and offers possibilities to enhance it without harming PHPCow core or already composed templates.

CTL benefits as template authors as PHP developers. Lets see what does it look like, and what useful features does it offers.

Variables

CTL has variable support, for example you can easily use them in your templates:

<html>
<head>
    My Template
</head>
<body>
    <h1>{var:site.title}</h1>
</body>
</html>

In the above example “{var:site.title}” variable will be replaced with “site” objects “title” property value.

Structure of variable syntax is very simple. It starts and ends with curly braces, and is prefixed by “var:” followed by variable name. This is standard notation that is really easy to remembers.

There are number of useful variables that can be used in templates. This way you can easily work with URLs, settings, post/get variables etc...

Functions

CTL functions work as other functions you know. For example, if we need to change case of letters we can use following function call:

My site title is: {fn:ucfirst(strtolower({var:site.title}))}

if value of “site.title” variable value is for example “THIS IS MY SITE”, function call first will change all upper case letters to lower case and than change the case of the first letter. After that on the screen will be printed following result:

My site title is: This is my site

from the example we can see that nested function calls are supported, and this is really grate feature. Though there is one restriction, not all functions can be called. This is partially is because security restrictions, and partially because not all functions return string values.

Structure of function call is easy as well. As with variables it starts and ends with curly braces, is prefixed by “fn:” followed by actual function name. Note that nested function calls doesn't require “fn:” prefix.

IF/ELSEIF/ELSE – Conditional structure

CTL offers support for if/eleseif/else conditional structures. This functionality is quite handy when customizing templates, because some of template parts could rely on some conditions.

<html>
<head>
    My Template
</head>
<body>
{if site.title != "null" and site.title != "bla bla bla"}
    <h1>{var:site.title}</h1>
{elseif site.title == "bla bla bla"}
    Site title is equals to "bla bla bla"
{else}
     we don't have site title
{/if}
</body>
</html>

Example above shows usage of if/elseif/else structure. It supports equals(==), not equals(!=), AND and OR logical conditions.

Syntax is quite simple to learn, and mimics to other known programming languages.

PHPCow Version 3 Preview

Posted On: July 19, 2008

Every PHPCow customer is interested in about status of the product's third version. Yes I know, it was very long since we didn't updated our product, but, we work really hard to release next version of our product and I want to introduce some of it's amazing features briefly.

First of all, PHPCow v3 is completely rewritten and it is tended to satisfy most of our current and potential customers needs and in this post I'll be concentrated on features of new Control Panel(CP).

We completely restructured CP and gave it more comfortable navigation and look and feel. You can really easy, just in few clicks achieve your tasks.

We divided control panel into sections and modules, each tab corresponds to particular section. Section itself consists of modules which are grouped in the left sidebar. Look at the picture below:

As you can see from the screenshot, currently we are located in the Administrator's section. This is the starting point after signing into the cp. First page is a dashboard from where you can easily navigate through other parts of the CP.

It is worth to mention that the new CP is completely Ajax based. All pages are built using rich components that allow you to effectively work with tasks that were very hard to achieve in previous versions. For example, bellow is a screenshot of Breadcrumb Management page from Navigation module:

Unlike previous version you can create/manage breadcrumbs without refreshing pages, changes applied to selected breadcrumb are visible immediately and even more you can arrange page components as you like(see popped out container on the right).

What is interesting with this particular example, is that every piece of new version shares same concepts and functionality. We developed powerful framework that gave us enough power to build really amazing control panel with rich user interface.

I'll show more details in the next posts. For now please comment you thoughts and opinions, your suggestions are highly appreciated.

Some Other Screens: