Tutorial - Template FLEXIcontent - Part4: The content of a template
In this fourth part I will present and explain the purpose FlexicontentViewItems that will allow us to achieve our template for Item. And so I will detail all the variables that can be helpful in building your own templates.
I will also talk about a lot of functions that can be found with the class flexicontent_html.
This tutorial is still built around my example want to display information about a football stadium.
Contents:
- The purpose FlexicontentViewItems
- Display a set of field from a position
- Displays a single field
- Management comments
- Do more ...
- item
- item-> fields or fields
- item-> positions
- use
- params
- menu_params
- The class flexicontent_html
- Function striptadsandcut
- Function extractimagesrc
- Function printbutton
- Function mailbutton
- Function pdfbutton
The purpose FlexicontentViewItems
This object usable in all template for Item will allow you to bring up all the information related to content.
It is accessible through the $ this variable.
I now resume my item.php file (created in part1 of this tutorial) and I will start by reviewing the header of my.
A 2 3 4 | / / Prohibits direct access to the file '_JEXEC' ) or die ( 'Restricted access' ) ; defined ('_JEXEC') or die ('Restricted access'); / / Set here the name of the template, in our case. Items.stade $this -> tmpl ; $ Tmpl = $ this -> tmpl; |
We will initiate our template then place a div tag by adding css class personalized according to the stage and type of content. For this I use:
$ This-> item-> id = returns the identifier of the content
$ This-> item-> type_id = returns the identifier of the type of content
It gives:
16
| $this -> item -> id ; ?> type <?php echo $this -> item -> type_id ; ?> "> <Div id = "stade_contenu" class = "item stade_contenu <? Php echo $ this -> item -> id;?> Type <? Php echo $ this -> item -> type_id;?>"> |
Display a set of field from a position
As we saw in part 1 of the tutorial, FLEXIcontent can manage different position where we can place our fields. This entitles the user to place these new fields without modifying the template code.
Just put in our template then a loop that will go through all the fields contained in a given position. Here is the code I would use for each of the positions that I created (header, address, contact, image, description, information, gmap, bottom):
17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <! - BOF header -> <div id="stade_entete"> ( isset ( $this -> item -> positions [ 'entete' ] ) ) : ?> <? Php if (isset ($ this -> item -> positions ['header'])):?> ( $this -> item -> positions [ 'entete' ] as $champ ) : ?> <? Php foreach ($ this -> item -> positions ['header'] as $ field):?> $champ -> name ; ?> "> <Div class = "Field_A <? Php echo $ field -> name;?>"> ( $champ -> label ) : ?> <? Php if ($ field -> label):?> $champ -> label ; ?> </div> <div class="etiquette"> <? php echo $ field -> label;?> </ div> ; ?> <? Php endif;?> $champ -> display ; ?> </div> <div class="valeur"> <? php echo $ field -> display;?> </ div> </ Div> ; ?> <? Php endforeach;?> ; ?> <? Php endif;?> </ Div> <! - EOF header -> |
Explanation:
isset ($ this-> item-> positions ['header']) / / indicates whether the fields are displayed or not in this position
php foreach ($ this-> item-> positions ['header'] as $ field): / / search all the fields content of the position
$ Field-> name / / returns the name of the field, I use it to declare a unique CSS class that will allow me then to format my field as I want
$ Field-> label / / returns the label of the field where I chose my settings in the field I chose to make it appear.
$ Field-> display / / displays the field value formatted according to the parameters that I set up (prefix + value + suffix)
Displays a single field
It is also possible to display a field directly without the position. This can sometimes be useful to make a simple template without any positions (which are heavier in terms of code). I will use this part of code to display my image "image_stade."
62 63 64 65 66 67 68 | <! - Soundtrack image -> <div id="stade_image"> <div class="champ_image_stade"> $this -> fields [ 'image_stade' ] -> display ; ?> <? Php echo $ this -> fields ['image_stade'] -> display;?> </ Div> </ Div> <! - EOF image -> |
To go directly to the values and parameter fields, use the $ this-> fields ['myfield'].
Management comments
I only get the original source code of FLEXIcontent to bring up the comments:
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | ( $this -> params -> get ( 'comments' ) ) : ?> <? Php if ($ this -> params -> get ('comments')):?> <! - BOF comments -> <div class="comments"> <? Php $this -> params -> get ( 'comments' ) == 1 ) : if ($ this -> params -> get ('comments') == 1): file_exists ( JPATH_SITE . DS . 'components' . DS . 'com_jcomments' . DS . 'jcomments.php' ) ) : if (file_exists (JPATH_SITE. DS. 'components.' DS. 'com_jcomments.' DS. 'jcomments.php')): JPATH_SITE . DS . 'components' . DS . 'com_jcomments' . DS . 'jcomments.php' ) ; require_once (JPATH_SITE. DS. 'components.' DS. 'com_jcomments.' DS. 'jcomments.php'); showComments ( $this -> item -> id , 'com_flexicontent' , $this -> escape ( $this -> item -> title ) ) ; echo JComments: showComments ($ this -> item -> id, 'com_flexicontent', $ this -> escape ($ this -> item -> title)); endif; endif; $this -> params -> get ( 'comments' ) == 2 ) : if ($ this -> params -> get ('comments') == 2): file_exists ( JPATH_SITE . DS . 'plugins' . DS . 'content' . DS . 'jom_comment_bot.php' ) ) : if (file_exists (JPATH_SITE. DS. 'plugins'. DS. 'content'. DS. 'jom_comment_bot.php')): JPATH_SITE . DS . 'plugins' . DS . 'content' . DS . 'jom_comment_bot.php' ) ; require_once (JPATH_SITE. DS. 'plugins'. DS. 'content'. DS. 'jom_comment_bot.php'); $this -> item -> id , 'com_flexicontent' ) ; JomComment echo ($ this -> item -> id, 'com_flexicontent'); endif; endif; ?> </ Div> <! - EOF comments -> ; ?> <? Php endif;?> |
Through $ this-> params-> get ('comments'), it allows me to retrieve the parameters of FLEXIcontent and so I have to show whether or not commantaires. (0 = no comments, 1 = 2 = JComments and Jom Comment)
FLEXIcontent can integrate the management comments of two components JComments (recommended) and Jom Comment.
So the parameters for the comments are directly managed via the component that is integrated.
Do more ...
Through the following chapters, I showed you how to display fields so basic, it may be that sometimes you need to go a little further into your template. Here are the most important information you can use in your template.
Item
This object contains all information about your content directly
A call in this way $ this-> item-> "ownership"
id | ID in the given base |
title | Title |
alias | Alias |
introtext | Introductory text (that corresponds to the description field is preferred) |
fulltext | Full text (that corresponds to the description field is preferred) |
state | State Publishing (1: published 0: Unpublished -1: archived, -2: deleted, -3: awaiting approval, -4: Draft, -5: in progress) |
sectionid | Section |
catid | Main Category |
created | Creation date |
created_by | Identifying the author |
created_by_alias | Alias of the author |
modified | Last updated |
modified_by | Id last author has amended section |
a.publish_up | Start date of publication |
publish_down | End date of publication |
version | Version Number |
ordering | Number indicating the rank order |
metaKey | Keywords meta data |
metadesc | Description of meta data |
metadata | Robots and Author meta data |
access | Level of access (0: public, 1: Private 2: Special) |
hits | Number of visits |
idem_id | Id content |
type_id | Identifying the type of content |
language | Language (en-US, en-US ...) |
search_index | All text is indexed for search |
cataccess | Access level of the category (0: public, 1: Private 2: Special) |
catpublished | Indicates whether the category is published or not |
author | Name of author |
usertype | Group name of the user |
typename | Label the type of content |
creatoremail | Email the creator of the original |
creator | Name of creator |
change | Name of last author having made a change |
text | Text (field description) to be displayed in the template (introduction or full text) |
cats | Table listing the categories associated (cats [x] -> id, cats [x] -> title ...) |
fields | See details in the next chapter item-> fields |
readmore_link | Way to link to the "read more» |
positions | See details in the next chapter item-> positions |
FieldValues | List the value of fields in a table (FieldValues [id_du_champs] [x]) |
favs | Number of users that have added the content in their favorite |
fav | Indicates whether the content can be placed in favorites |
vote | Object with the following values: rating_sum (average value of votes), rating_count (votes) lastip (ip voting last address). |
item-> fields or fields
This way you can get all the information about the fields in your template, either for the core fields (title, text, but all your custom fields (such as you have named) that are associated with the type being displayed.
A call in this way $ this-> item-> fields ['field name'] -> "property" or so $ this-> fields ['field name'] -> "ownership"
id | Id field |
field_type | Field Type |
name | Field Name |
label | Label of field |
description | Field description |
IsFilter | This field is there a filter? |
iScore | |
isearch | The field is being used for research |
isadvsearch | The field is used for advanced search? |
published | Published or not |
access | Access level (0: public, 1: Private 2: Special) |
ordering | Number indicating the rank order |
value | Value table entry field |
display | Viewing the formatted value of the field. |
Each field also has parameters that can be recovered in this way (subject JParameter):
$ This-> item-> fields ['field name'] -> parameters-> get ('parameter')
Here are the main parameters that can be found, not all are used depending on the type of field.
display_label | Display panel |
remove_space | Remove spaces |
Pretext | Prefix |
posttext | Suffix |
default_value | Default |
allow_multiple | Allow multiple values |
MAX_VALUE | Maximum value |
size | Field Size |
separatorf | Separator values for the frontend |
OpenTag | Previous tag value |
closeTag | Tag succeeding value |
date_format | Standard display format of date |
custom_date | Custom display format of date |
rows | Number of rows in a textarea |
passes | Number of columns in a textarea |
use_html | The HTML editor is enabled? |
item-> positions
As discussed previously you can browse through all positions of a template to display your fields. Here is the detailed information you can use.
A call in this way $ this-> item-> positions ['name of position] [' field name '] -> "ownership"
id | Id field |
name | Field Name |
label | Label of field |
display | Formatted value of the field |
use
This object type juser gives you information about the currently logged
A call in this way $ this-> user -> 'property'
id | ID of the user |
name | Name |
username | User login |
Email address of the user | |
usertype | Type of User |
registerDate | Date of registration |
lastvisitDate | Date of last connection |
params
It is an object JParameter that will allow us to find the parameters related to the content.
$ This-> params-> get ('parameter')
flexi_section | Section associated with FLEXIcontent |
comments | Enable input (0 = no comments, 1 = 2 = JComments and Jom Comment) |
support_url | Support URL |
flexi_fish | Enable support Joomfish |
filtercat | Filter categories views |
filtertag | Filter views tags |
use_versioning | Enable versioning |
nr_versions | Versions kept |
show_title | Title of content |
link_title | As clickable |
show_readmore | Link Read more ... |
show_icons | Icons |
show_pdf_icon | PDF icon |
show_print_icon | Print icon |
show_email_icon | Email icon |
limit | items per page |
catlimit | Limit lists (categories) |
upload_extensions | Allowed Extensions (File Types) |
upload_maxsize | Maximum size |
file_path | Secure path to the directory |
media_path | Media path to the directory |
restrict_uploads | Restrict uploads |
check_mime | Check MIME types |
image_extensions | Extensions of images allowed (File Types) |
ignore_extensions | Extensions ignored |
upload_mime | MIME types allowed |
enable_flash | Enable upload Flash |
feed_summary | For each RSS feed |
advcache | Advanced Cache |
advcache_time | Duration of the cache |
advcache_guest | Visitors only |
disablecss | Disable CSS |
item_depth | Item Level |
add_item_pathway | Add to path |
show_page_title | Page Title |
menu_image | Menu image |
secure | Active SSL |
page_title | Show the title of the page |
page_description | Meta description |
menu_params
It is an object JParameter that will allow us to recover the parameters associated with the menu of the contents that must be displayed.
$ This-> menu_params-> get ('parameter')
item_depth | Item Level |
add_item_pathway | Add to path |
page_title | Page Title |
show_page_title | Show the title of the page |
pageclass_sfx | CSS Class Suffix |
menu_image | Menu image |
secure | Active SSL |
The class flexicontent_html
This class of FLEXIcontent offers some useful features for our templates.
Function striptagsandcut
This feature allows us to remove html tags from a text and cut cleanly after a certain number of characters.
/ / This example will format and truncate after 100 characters $ my_text striptagsandcut ( $mon_texte , 100 ) ; echo flexicontent_html: striptagsandcut ($ my_text, 100);
Function extractimagesrc
This feature allows us to generate an image tag from a field of type image.
/ / This example will format and truncate after 100 characters $ my_text extractimagesrc ( $this -> fields [ 'mon_champ_image' ] ) ; echo flexicontent_html: extractimagesrc ($ this -> fields ['mon_champ_image']);
Function printbutton
This function displays the button and the link to print the current content
/ / This example will display the Print icon in our content printbutton ( $this -> print_link , $this -> params ) ; echo flexicontent_html: printbutton ($ this -> print_link, $ this -> params);
Function mailbutton
This function displays the button and the link to recommend active content in mail
/ / This example will display the icon Send mail to our content mailbutton ( 'items' , $this -> params , null , $this -> item -> slug ) ; echo flexicontent_html: mailbutton ('items', $ this -> params, null, $ this -> item -> slug);
Function pdfbutton
This function displays the button and the link to generate active content in pdf
/ / This example will display the icon in our PDF content pdfbutton ( $this -> item , $this -> params ) ; echo flexicontent_html: pdfbutton ($ this -> item, $ this -> params);
This is the fourth game is over, the next time I will address the templates category. Once again please make your comments or to ask questions if you do not understand something.













On 24/02/2010 at 09:18, Emmanuel Danan said:
Wow, what synthesis
One word: BRAVO!
Thank you to you for this new contribution.
Manu.