The Joomla! Forum ™





Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Parameters for layouts
PostPosted: Sun Aug 26, 2007 10:49 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Aug 15, 2007 8:26 pm
Posts: 10
Location: Silesia
For every layout there can be set of parameters defined in [layout_name].xml file. Is there any documentation for this configuration file? Where are those values stored? How can I access them?

When I'm creating menu item for 'Category Blog Layout' I can choose the category I'm referring to ('Parameters - Basic' section). Can I create similar select item for my components?

I think Joomla! 1.5 needs a good, complete and nontrivial tutorial for new component developers. Those that I've found are too simple and doesn't cover all aspects of this matter.

_________________
http://www.rajchman.pl/


Top
 Profile  
 
PostPosted: Sun Aug 26, 2007 11:23 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Aug 15, 2007 8:26 pm
Posts: 10
Location: Silesia
Ok. I've found this (blind fool):

http://dev.joomla.org/component/option, ... arameters/

I have also created a JElement class for my component. Now I only need to inform Joomla! where to find it.

_________________
http://www.rajchman.pl/


Top
 Profile  
 
PostPosted: Mon Aug 27, 2007 12:05 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Aug 15, 2007 8:26 pm
Posts: 10
Location: Silesia
So, to create your custom parameter type and use it in your layout you have to:

1. create a class that extends JElement
Place this file into adminstrator/components/sdp_[component_name]/elements/ directory.
Name this file as [element_type].php

Example of czlonek.php file:
Code:
<?php
defined('_JEXEC') or die();

class JElementCzlonek extends JElement
{
   var   $_name = 'Czlonek';

   function fetchElement($name, $value, &$node, $control_name)
   {
      $db = &JFactory::getDBO();

      $query = "SELECT concat(czlo_nazwisko,' ',czlo_imie) AS text, czlo_id AS value FROM #__czlonkowie"
      .' ORDER BY czlo_nazwisko, czlo_imie';
      $db->setQuery($query);
      $options = $db->loadObjectList();
      array_unshift($options, JHTML::_('select.option', '0', '- '.JText::_('Select Czlonek').' -', 'value', 'text'));

      return JHTML::_('select.genericlist',  $options, ''.$control_name.'['.$name.']', 'class="inputbox"', 'value', 'text', $value, $control_name.$name );   
   }
}
?>

This class just creates select html tag with all items of 'czlonkowie' table.

2. create XML parameters file for your layout (name this file [layout_name].xml)
Now you can define param with argument type set to your custom type (type="czlonek"). My layout's name is 'default' so paramter's name will be 'default.xml'.

Code:
<?xml version="1.0" encoding="utf-8"?>
<metadata>
   <layout title="Członek SDP">
      <message>
         <![CDATA[CZLONEK DESC]]>
      </message>
   </layout>
   <state>
      <name>Standard Członek Layout</name>
      <description>CZLONEK DESC</description>
      <url addpath="/administrator/components/com_sdp/elements">
         <param name="id" type="czlonek" section="com_sdp" default="0" label="Czlonek" description="PARAMCZLONEKSELECT" />
      </url>
      <params>
      </params>
   </state>
</metadata>

Tag named 'url' defines additional attributes that Joomla! will add to url. Inside this tag I define my custom parameter (remember to set type to your new JElement). Set name attribute of param tag to the name of your additional url parameter.

'Label' and 'description' attributes are not so important. I think that 'section' attribute is not needed in this case - I don't have any sections in my 'czlonkowie' table.

The last thing you have to to is to inform Joomla! where it can find your JElement class. All you have to do is to add addpath attribute to 'url' tag.

addpath="/administrator/components/com_[component_name]/elements"

And that's all. It works for me :D.

PS: If there is something wrong with my English please correct me.

_________________
http://www.rajchman.pl/


Top
 Profile  
 
PostPosted: Mon Aug 27, 2007 4:11 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Thu Aug 18, 2005 1:50 am
Posts: 325
Location: New Orleans
You did a fine job there. Thanks for sharing this information

_________________
This day it is my wish that I helped you to live


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 



Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group