gdT3: Rendering Templates System – Basics

gdT3 is a rendering system based on templates developed by Dev4Press and currently used in several plugins, with few more getting it soon. GD Products Center Pro currently uses for template classes to render: single product, archives, compare and products list panel.

Very important thing is not to confuse the rendering templates for gdT3 with theme templates used by WordPress.  To avoid confusion, all rendering gdT3 templates have different naming convention. Name has 3 parts: class name, template name and extension. Extension must always be ‘.inc’. Name for the template must be unique to closely identify the template. Classes needed by GD Products Center are:

  1. archive:  used for products archives pages
  2. compare: used for the comparison page
  3. products: used for special products types list page
  4. single: used for single products.

Template Content

For plugin to use the template, template needs a required structure and first 5 rows in each template are used for this purpose. All these rows are starting with @@@ characters. All 5 are required always. This is a typical structure for one template and it’s first 5 rows:

[code]@@@:NAME:Filter Grid:@@@
@@@:CLASS:archive:@@@
@@@:SCOPE:public:@@@
@@@:DESCRIPTION:Full filtering for products using grid layout for display.:@@@
@@@:BLOCK:main:@@@[/code]

As you can see, each row must begin with @@@: and end with :@@@. Each row must have uppercase name and value after that. First row is for template name. This is a display purpose name, a short description of the template. Second row is a class name, and it must match the template file name class. Scope can be private or public. Public templates will be listed for selection on various interface panels. Description is detailed information about the template. Block always must be set to main.

Each template can contain HTML, PHP and special rendering tags implemented by the plugin. These tags can be very complex, and they will be covered in different tutorials.

Templates Locations

All default templates built in GD Products Center Pro are located in the folder ‘tpl’.  If you want to create your own templates, best is to start with one of the default templates. Also, do not edit default templates directly in plugin folder, any change you made will be gone after you update the plugin. If you use same name for the template as the existing one, than your template will replace default one. Plugin has a panel where all public templates available to plugin are listed:

List of available gdT3 templates
List of available gdT3 templates
Extra templates locations
Extra templates locations

There are two ways to specify where are your templates located. One is with the filter hook and other one is through plugin settings. Each template in the settings list must be relative to the WP-CONTENT folder. If you want to use filter, you can add list of your templates location(s) through code. Example for this is in the block below:

[php]add_filter(‘gdpc_init_templates_storage’, ‘add_my_templates_storage’);
function add_my_templates_storage($list) {
$list[] = WP_CONTENT_DIR.’/uploads/my-templates’;
return $list;
}[/php]

If you want just to make changes to default templates, best thing is to use same template names, and in that case your template will override original template. So, let’s say you want to make changes to archive.filter-grid.inc template. Copy the original file to your templates location and make changes to it. Rescan templates to make sure that new locations are loaded and that’s it, plugin will use new template.

If you want to have access to default templates, and to have your own, you can rename template in your location to something like:  archive.my-filter-grid.inc. Don’t forget to change name and description in the template.

Comments

Leave a Reply