Extending Community Answers Using Template System

Community Answers allow you to extend the template without loosing the work you've done when upgrading the component. Before moving forward, below are few facts about the template framework of Community Answers.

  • Community Answers uses jQuery framework for all Ajax and user interaction. The required jQuery and jQuery UI libraries will be loaded from the assets/scripts directory when the component is loaded.
  • Community Answers stores default template under components/com_communityanswers/templates. The default folder stores the default template and required files.
  • Community Answers has the mechanism to load your css and JavaScript  files automatically from the templates. You need not include your scipts or styles manually. All you need to do is to place the scripts and styles in appropriate directories which you will learn later in this article.
  • When extending the templates, you need to copy all resources from the template you are extending into your custom template. This includes images, scripts and styles etc.
  • The custom template location of Community Answers is JOOMLAROOT/templates/communityanswers/ .
So here is the procedure to extend the default template that is part of the Community Answers package (components/com_communityanswers/templates/default)

  1. Copy the template directory "default" from the templates folder to the custom templates folder Do not rename the folder for now as you are extending the default template and want to keep the name as is.
  2. Keep the template files (*.php files) that you want to customize and remove all other .php files in your custom template folder. Below are the template files which you may be interested in:
    1. open_answers.php - The home page of community answers. Displays open, answered, featured, most answered answers etc.
    2. view_answer.php - This page displays the individual answer
    3. new_answer.php - This page displays form for posting new question
    4. user_answers.php - Lists the answers submitted by the logged in user that he owns
    5. user_questions.php - Lists questions submitted by logged in user that he owns.
  3. The Community Answers template system is intelligent enough to take the available template file from your custom template folder/template folder/default template folder. It looks for a template file in the sequential order of the following locations:
    1. JOOMLAROOT/templates/communityanswers/TEMPLATENAME folder where TEMPLATENAME is the name of your custom template (for now you can treat this as default as your custom template is extending from default template).
    2. components/com_communityanswers/templates/TEMPLATENAME folder
    3. components/com_communityanswers/templates/default folder
  4. Now if you want to customize only home page of Community Answers, just keep open_answers.php file and remove other template files. Please note that you still need to keep all resources that you copied from default template
  5. Now customize the template file as you wish and Community Answers loads your template instantly.
Below are the variables available that you can make use of:
$this->list - Array stores the list of questions. Each question is a PHP object with the following properties
  • id - id of the question (number)
  • title - title of the question (string)
  • description - description (string)
  • alias - alias for sef urls (string, sef safe)
  • catid - category id (number)
  • category - category name (string)
  • catalias - category alias (string sef safe)
  • published - 1 = published , 0 = unpublished (number)
  • answers - total number of answers this question has received so far (number)
  • created_by - user who created the question (number)
  • created - date created in the format "mm-dd-yyyy hh:mm:ss" (string)
  • ip_adress - ip address of the creator (string)
  • $this->category  - category id if your are viewing specific category

Always use $this->escape($YOUR_STRING_VARIABLE) function when you are printing a string variable for security reasonsEx: echo $this->escape($row->title);
  • Friday, 09 July 2010

Random Poll

What feature do you like in Joomla CMS?
Joomla is the most used Content Management System across the world. Millions of websites build on the great CMS. Which feature do you like the most on this beautiful CMS? Please share your comments and experiences in the comments section.
660188159 [{"id":"83","title":"Easy to use interface which allow even novice to start using it within less time","votes":"60","pct":"23.17","type":"x","order":"0","resources":[]},{"id":"84","title":"Extensive list of community extensions and templates","votes":"62","pct":"23.94","type":"x","order":"0","resources":[]},{"id":"85","title":"Support from the Joomla forums","votes":"39","pct":"15.06","type":"x","order":"0","resources":[]},{"id":"86","title":"Security Features","votes":"47","pct":"18.15","type":"x","order":"0","resources":[]},{"id":"87","title":"Administration Control Panel & Dashboard","votes":"24","pct":"9.27","type":"x","order":"0","resources":[]},{"id":"88","title":"Compatiability with the older versions of Joomla","votes":"27","pct":"10.42","type":"x","order":"0","resources":[]}] ["#ff5b00","#4ac0f2","#b80028","#eef66c","#60bb22","#b96a9a","#62c2cc"] gpie 200 200 /demos/polls/vote/34-what-feature-do-you-like-in-joomla-cms.html No answer selected. Please try again. Thank you for voting. Answers Votes ...

25% Off Coupon

Joomla runs best on HostGator. Get 25% off on your hosting bill at hostgator with coupon code COREJOOMLA25OFF.
Sign up now.

Newsletter

We do not spam your mailbox. Product updates/offers, security updates etc. will be sent.
captcha
Terms and Conditions