Twitter
Mon
31
May
'10
PDF
Print
Send
 
Hits (3047) | Comments (9) | Favorited (4) | Votes (0)

Here is what changes was done in 1.5 version and what you should check and fix in your extensions or templates to be compatible with 1.5 version.

FIELDS ARRAY

You know that it used to be the $this->fields array that contained all fields values and also $this->ifields array with the same information but indexed by title of the field. In new version it is changed.
First you have to know that old way should continue working without any problems. So actually you do not need to change anything unless you wish to make your template 100% compatible or you start create new template.

New way to access field information directly is through $item object. No matter if it is list template or article template you finally get $item variable that contain article information.

For example in list template you get it like this.

for ($c=0; $c<count($this->items); $c++):
    $item = @$this->items[$c];
 

And in article template you get it like this

$item = $this->article;
 

That is like it always was. But here is new way how you can access field information directly like this

<?php if(@$item->fields[23]): ?>
    <span><?php echo $item->fields[23]->result; ?></span>
<?php endif; ?>
 

1. Do not forget @ before $item variable. Because if field if not required and user not filled it out there will not be such index in fields array.

2. 23 is an ID of the field that you may find in the list of the fields of the article type. Index fields by IDs is much better than by titles. It turn out to be that sometimes there are different fields with the same titles in one type and not everyone can understand how to save custom template in UTF format in order for titles to be appropriate.

If you want list fields universally, then look joomla_blog template how it is done there.
Important to know that for Section Pack feature, if you want to pack templates to the Pack, you need to use this method only.

When user install your pack, in his Joomla DB fields IDs are different because he may already has same IDs that is saved in your pack. So new IDs assigned automatically and saved. Template after copy is processed with ereg_replace everything like ‘/->fields[([0-9]*)]/iU’ and ID will be replaced with just new assigned.

Also if in template parameters you use parameters to select field the parameter name SHOULD contact field_ in it. Examples tpl_map_field_address, tpl_field_logo. Then you may use this in template to call field

<?php echo $item->fields[$this->params->get(‘tpl_map_field_address’)]->result; ?>

To find out more about Section Pack, go to tools and run Section Pack tool to find out what it is.

FORM FIELDS

You know that form templates could accept $this->ifields variable for custom form templating. This will be supported in 1.5 but not native any more. Now only $this->fields array is official. And you can use it to call directly and fetch in cycle.

Example of direct access

<?php echo $this->fields[24]->result; ?>
 

And example of cycle you can find in default form template.

This is changed in all form templates and no longer will work correctly through old way of display field through

<?php ResViewRecord::renderField($field); ?>

But that is easy to fix. Just change all

<?php ResViewRecord::renderField($field); ?> 
 

to

<?php echo $field->result; ?>

in you custom templates.

COLUMNS

If you created or want to create table style list template, then you should to know changes done to column variable.

First note that old columns way should continue to work also so this is for compatibility wish or new template.

There was 2 column variables. $this->cols and $this->cols_additional. It is not matter what was in there but now it is replaced with 1 variable named $this->columns. It is an array. Each element(column) contain array with 3 indexes.

foreach ($this->columns AS $column)
{
    $title = $column['title'];
    $field_id = $column['id'];
    $field_params = $column['params'];
}

Using this variable you can create universal list template of table stile. But it is not applicable really. The one universal template we have is enough almost everywhere.

If you make table style template better use direct fields call and fixed columns in table.

ARTICLE TEMPLATES

Now there is new feature. You can reposition comments in to article template. For example you want your article template be in 2 columns. 1st column is an article and 2nd column is a comments. You can do it easilyby placing following code anywhere in article template.

<?php if($this->params->get('comments')):?>
        <?php echo $this->loadTemplate('comments');?>
<?php endif; ?>

Another feature is to load module just inside temple. It is also usefull for creating templates like Youtube where similar and the same author videos displayed and in Joomla that would be modules. Also for creating commerce sites for example you want to show “Those who buy this also buys” module in article detail only. It is hard to do with Joomla Itemid system. But if you call needed module just inside template you know that it will appear only in that particular place. And if user lose Itemid somehow (which is known fact it happens)   it will be there anyway.

To call any module position use this

<?php echo load_module_position('myposition1', ‘table’); ?>
 

First parameter is the name of position to load and you can name it as you want. But not forget to add this position to your Joomla template XML file (templateDetails.xml) to <positions> tag to make this position available to place modules in to it. Second parameter is the style which is used to display module. It is absolutely the same parameter if you use it in Joomla template in style attribute like this

<jdoc:include type="modules" name="user1" style="rounded" />
 

It may have values: rounded, table, xhtml, horiz, none

TEMPLATE PACKS

When you style your template and you need any CSS for template just create .css file  with the same name as template file and it will be automatically linked to page. The same rule applies to java script. If you have JS you can create .js file and it will be automatically loaded.

Store all your images that is used by template in folder with the same name like template file.

Those rules are required if you want to get proper Section Pack. Only this scheme allow guaranty include to Pack all of template and work correctly.

NEW ELEMENTS

Added 2 new elements that can be used in every template. It is a list of categories and user category.

<?php if($this->params->get('item_categories')):?>
    <span class="small">
         <?php echo (count($item->categories) > 1 ? JText::_('Categories') : JText::_('Category')) ?>: 
         (<?php echo implode(" | ", $item->categories);?>)</span>
     <?php endif;?>
     <?php if($item->user_category):?>
         <span class="small">
              <?php echo JText::_('User Category') ?>: (<?php echo $item->user_category;?>)
         </span>
<?php endif;?>
 

URLS

Important changes are in URLs creation. If you create URL to category or article you need to use

$link = MEUrl::link_list($category_id);
$link = MEUrl::link_article($article_id, JRequest::getInt(‘category_id’));
 

$urls other than those should follow this rule.

1. To get correct Itemid use MEUrl::itemid(NULL, $category_id);
2. Add addition to any URL with MEUrl::linkAdditions($link);

Example

$link = 'index.php?option=com_resource&amp;view=category&amp;category_id=' . 
     $category_id . '&amp;Itemid=' . MEUrl::itemid(NULL, $category_id);
$link = MEUrl::linkAdditions($link);

 


Comments
VilioAvatar
Quote
- -
Written by Vilio VIP on 29 July 2010

hello,

I would like to ask, if there is possible to check what kind of field is for example field with ID 23. I want to create own template and if there is picture present, I want to put it on left, remaining text on right. If I set ID to xx and I will use different type it will not work.

-
SerhioAvatar
Quote
- -
Written by Serhio STAFF on 30 July 2010

If you create multi type custom template you ought to use SWITCH statement to find out what type is loaded into template right now. 

And you can also quickly find what is the type of the field

if($item->fields[23]->type == 'picture')
{
   echo $item->fields[23]->result;
}

 

-
VilioAvatar
Quote
- -
Written by Vilio VIP on 30 July 2010

Do you have somewhere documented what members and functions contain item class ?

-
VilioAvatar
Quote
- -
Written by Vilio VIP on 03 August 2010

Also I'm interested how to access value in field. for example. I have simple select field with values:

Discount

Sell off

Member price

When I access $item->field[23]->result I have output with html around. How can I check which option is choosen in simple select ?

Do you have list of members for item class with description what data are they holding ?

-
SerhioAvatar
Quote
- -
Written by Serhio STAFF on 04 August 2010

trim(strip_tags($item->field[23]->result))

-
SerhioAvatar
Quote
- -
Written by Serhio STAFF on 04 August 2010

How to see all properties of $item

<pre>
<?php print_r($item); ?>
</pre>

-
neoketsordAvatar
Quote
- -
Written by neoketsord VIP on 07 November 2010

Hi there,

After updating to 1.5, my custom developed fields do not work anymore. Those fields just don't show up within the article anymore. The @$item->fields[24] call does not even recognize that the fields exist. In the backend the fields work fine.

What do I need to change in the PHP of my fields to make it work again?

Thanks,


Koen

-
snooky147Avatar
Quote
- -
Written by snooky147 VIP on 13 November 2010

Hi, I test 1.5 and think all my template work on 1.4 is lost ?

Can't use anymore : <?php echo $this->ifields[$key]['field name'];?>

Is it right ? because if you have a lot of field, you can remember all names, but all ID !!!??

I 'm not enjoyed to rebuild all my templates ! so much work before (PHP gives me headake)

-
jacques_vAvatar
Quote
- -
Written by jacques_v VIP on 22 February 2011

On the last paragraph, you write:

$link = MEUrl::link_article($article_id, JRequest::getInt(‘category_id’));

 

link_article doesn't exist in this class. Use link_record instead.

$link = MEUrl::link_record($article_id, JRequest::getInt(‘category_id’));

-
Add New Comment
Name:
Email:
Comment:
Attachment
Hide Comment
Security code:
Enter text as you see on image
 
 
What is best way for Download/Installation MightyExtensions?
 


Member Area



Member Activity

We have 1926 guests and 7 members online


MightyTemplate - Professional Joomla Templates