Quick templating tutorial for Ads Factory.
Ads Factory includes a very powerful template engine - smarty. We will try to cover in this tutorial the essentials of building a template for Ads Factory using this Template Engine. By far this cannot cover the extensive manual of smarty. Making use of smarty, the ads engine will provide to this engine some pre-filled objects and arrays of objects that are relevant to the current page displayed. Also all language constants defined in Ads Factory can be accessed in the template. We advice against writing hard coded text into the Templates, since this would render the multi language concept useless. If you do not care about the ability to translate your site, then you can do as needed.
This tutorial is addressed to the HTML savvy webmaster that need to change the default appearance of Joomla's Ads Factory Component. For most users the default template should contain all the necessary information.
First of all, what is a template engine?
A (web) template engine is software that is designed to process web templates and content information to produce output web documents. It runs in the context of a template system. It is practically a php script that interprets some kind of pseudo HTML pages containing placeholders for specific variable content.
In order to update much easier, we recommend that you note all the changes made on the templates, then apply them on each update in order to avoid any issues!
1. Where are the files and what can be changed?
All template files are in the components/com_adsfactory/templates folder, further sorted by folders which have the template's names.
The components/com_adsfactory/templates/cache folder contains the pre-processed files and normally you should not have to edit or delete something in it. We recommend that this folder has writing rights for PHP scripts, so the engine can improve the speed by caching the templates.
Main Template File | Description |
---|---|
ads_template.css | Component css file |
t_categories.tpl | Category list template |
t_catselect.tpl | Template for category selection, used on t_editad.tpl |
t_creditoffers.tpl | Display of available credit offers |
t_details_ad.tpl | Contains the template for displaying the Ad Item details page |
t_editad.tpl | Used to display the page for "New Ad" and "Edit Ad". The $task smarty variable contains the current task (newad or editad) |
t_friend.tpl | Template for Tell a Friend page |
t_googlemap.tpl | The Google map template included / or not (can be configured) in ad detail page |
t_googlemap_tool.tpl | Google map selector for user profile page |
t_javascript_language.tpl | Javascript bridge for language strings. Should not be modified in most cases and should be included in most templates |
t_listadds_header.tpl | Header template used for t_listads.tpl with filtering options |
t_listads.tpl | The regular mode listing template |
t_listads_grid.tpl | The grid mode listing template |
t_myads.tpl | The regular mode personal ads listing template |
t_myads_grid.tpl | The grid mode personal ads listing template |
t_myuserdetails.tpl | My user details template |
t_mywatchlist.tpl | The regular mode favorite ads listing template |
t_packageoffers.tpl | Display of available package offers |
t_reportad.tpl | Template for reporting an ad page |
t_search.tpl | Template for the search page |
t_userdetails.tpl | User view details template |
t_watchlist.tpl | The regular mode favorite ads listing template |
t_watchlist_grid.tpl | The grid mode favorite ads listing template |
2. Basic smarty knowledge.
All smarty templates are pure HTML. What the template engine needs to interpret must be put in accolades { }, a so called smarty tag. If the smarty contains a variable or a constant, then smarty just replaces it with its value. for instance this tag {$task} will be replaced with the current Joomla task (for instance with "newad" - without the quotation marks).
Smarty also allows IF clauses, so you an branch out two different displays depending on a condition. So for example {if $task=='newad'}You are creating a new ad{else}You are editing an existing ad{/if} will display one of the two texts depending on the current task. Another useful smarty command is {include file='xxxxx'} - this includes another smarty template file. For instance it is useful for us in the matter of including the necessary Javascript for the ads. Since most pages use the same Javascript codebase we can have just a single page containing these statements. For assigning a value to a variable (if the variable does not exist, it will be created) you have to use {assign var=variablename value='VALUE'} in this way you may use smarty for advanced templating techniques that resembles more with programming.
3. Custom defined smarty functions for Ads Factory.
Since Smarty is a very powerful tool for templates, we can create custom functions that can be called out from templates. Functions that are not in the standard distribution of smarty. We created following functions that can be used especially for our purpose (Ads).
4. Variables that are ALWAYS initialized:
5. Ads Variables initialized in specific pages.
5.1. Variables initialized in Ads Details and Ads listings.
For ads detail the main object is called $ad, in ads listings will be a similar object called $item. The properties of $ad from detail page and $ad from list are similar.
5.2. Listing Pages
Favorites listings, my ads are including listing template. For custom templating you can just copy the content from listing template into favorites and modify it.
{$item}
otherads, details, edit, republish, cancel, user_profile, report, filter_cat, add_to_favourite, del_from_favourite, terms, tags (text tags)
5.3. Category Page.
Display listing of categories as tree. Array {$categories} contains objects of categories with subcategories with same structure. Array () of
(!) Documentation based on Ads Factory version 4.4.0