any introduction/examples with patTemplates in Joomla 1.1

A general technical discussion area for patTemplate.
Locked
User avatar
magentait
I've been banned!
Posts: 519
Joined: Tue Aug 30, 2005 11:53 am
Location: Norway
Contact:

any introduction/examples with patTemplates in Joomla 1.1

Post by magentait » Sat Mar 11, 2006 5:20 pm

I'm a Joomla template developer, and I've been looking at the patTemplate webpage (http://www.php-tools.net/). But I can't find any good documentation on how to implement patTemplates in Joomla, and why on earth using patTemplates? Could anyone give me some good examples and documentation on how to start developing patTemplates in Joomla?

Is the Joomla patTemplate library finished?

Is it an easy way to convert Joomla 1.0.x templates to patTemplates (Joomla 1.1)?

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: any introduction/examples with patTemplates in Joomla 1.1

Post by ianmac » Tue Mar 14, 2006 5:29 pm

Hi,

The patTemplate library is primarily for component and module development at this point.  It is not really the same thing as Joomla! Templates.  patTemplates are used in components so that business logic and presentation logic can be separated.

It sounds like you are talking more about Joomla! Template development, which I don't think has altogether changed that much, though I've never done serious template development (only minor modification to existing templates).  To see how 1.1 templates are structured you might look at the template included in the 1.1 release, though I don't know how updated it is.

Ian

User avatar
Scribe
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 242
Joined: Wed Feb 01, 2006 9:14 pm

Re: any introduction/examples with patTemplates in Joomla 1.1

Post by Scribe » Tue Mar 14, 2006 5:50 pm

From what I've seen in the 1.1 templates the structure of tempates has changed to be more 'template' oriented. Rather than using lots of included PHP code containing things like mosLoadModules it contains things like . The included template that I saw did still have a bit of php code for conditional layout based on the old mosCountModules routine.

I think migrating away from embedded php code is good but I haven't had time to look into it much or see if it's backwards compatible with existing mosLoadModule() type calls or what type of functionality is available with this new jdoc interface.

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: any introduction/examples with patTemplates in Joomla 1.1

Post by ianmac » Wed Mar 15, 2006 5:12 am

But IMO, for a template developer this seems like a fairly trivial change...  instead of a you now have ...  this doesn't sound like it would be that difficult to convert...

my $.02

Ian

User avatar
Scribe
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 242
Joined: Wed Feb 01, 2006 9:14 pm

Re: any introduction/examples with patTemplates in Joomla 1.1

Post by Scribe » Wed Mar 15, 2006 5:22 am

Nope, pretty simple stuff!

User avatar
torkil
Joomla! Guru
Joomla! Guru
Posts: 726
Joined: Wed Aug 24, 2005 9:34 am
Location: Rørvik, Norway
Contact:

Re: any introduction/examples with patTemplates in Joomla 1.1

Post by torkil » Wed Mar 22, 2006 12:33 pm

I could not locate any introductory examples in the dev wiki as to how to make good use of patTemplate in component developing. Could anyone give a few pointers? Or maybe some examples of core components that use this already in J!1.5?

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: any introduction/examples with patTemplates in Joomla 1.1

Post by ianmac » Wed Mar 22, 2006 1:15 pm

I haven't seen any of the core components using patTemplates yet...

Here is a basic outline of how I have implemented them in the component I am working on:

In my file admin.component.html.php I have:

class HTML_component {
    function show( $option, &$rows, &$pageNav ) {
        $displayrows = array();
        $k = 0;
        foreach ($rows as $row) {
            $displayrows[] = array ('num' => $k, 'item_id' => $row->id, 'item_title' =>$row->name, 'link_target' => 'index2.php?option='. $option .'&task=editA&id='. $row->id .'&hidemainmenu=1' );
            $k++;
        }
        if (!$oTmpl = JTemplate::getInstance()) {
            echo "Failed to get template instance!";
        }
        $oTmpl->parse( 'page.html' );
       
        $oTmpl->setRoot( dirname(__FILE__).'/tmpl/' );
        $oTmpl->parse( 'adminlists.html' );
        $oTmpl->parse( 'component.show.html' );

        $oTmpl->addVar( 'component_show', 'listfooter', $pageNav->getListFooter() );
        $oTmpl->addVar( 'component_show', 'option', $option );
        $oTmpl->addVar( 'component_show', 'total_rows', $k );
        $oTmpl->addVar( 'component_show', 'k', $k );
       
        if ($k) {
            $oTmpl->addRows( 'list-items', $applications );
        } else {
            $oTmpl->setAttribute( 'list-items', 'visibility', 'hidden' );
        }
       
        $oTmpl->display( 'component_show' );
    }
}

Then in my component.show.html I have:











#


           

                Name
   
   
   
        {PAT_ROW_VAR}
       
       
   
   
   

    {LISTFOOTER}











and in my adminlists.html (this is a customized version of the one from the core because the one from the core didn't seem to be working...  I don't think it is finished yet - so this is the core adminlists.html with a few mods)


@version $Id: adminlists.html 558 2005-10-19 12:07:41Z eddieajau $
@package Joomla
@copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
@license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
Joomla! is free software. This version may have been modified pursuant
to the GNU General Public License, and as distributed it includes or
is derivative of works licensed under the GNU General Public License or
other free or open source software licenses.
See COPYRIGHT.php for copyright notices and details.











{PAGE_LINKS}




Display Num
{PAGE_LIST_OPTIONS}
{PAGE_COUNTER}






   


{ITEM_CHECKED_OUT_TIME}Click to check in')">






   



    {ITEM_TITLE}





Free" border="0" />



Sticky" border="0" />






Unpublished" border="0" />



Published" border="0" />





{ITEM_ORDERUPICON}


{ITEM_ORDERDOWNICON}









I had been working on a template file that would replace the mosHTML class, but I think I was going about it the wrong way, so back to the drawing board...  there are some things in this code that are kind of hackish, so please excuse that.  But this should give you a general example of one way to implement patTemplate in your component.  I would encourage you to share your findings as you work through it and learn more...  It would be very helpful to have some good resources on this.

Ian

User avatar
Scribe
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 242
Joined: Wed Feb 01, 2006 9:14 pm

Re: any introduction/examples with patTemplates in Joomla 1.1

Post by Scribe » Wed Mar 22, 2006 7:47 pm

Thanks for the example, I'm just beginning to look at patTemplates. I held off for a while thinking that some of the existing modules would be converted in 1.1 but I it's time to jump in. So, from your experience so far, what do you feel the benefit is over just hardcoding the way most of the modules are done now. I've done some stuff with Smarty in the past but must confess I typically just use variable substituion inside html templates with generically named styles to format the output. What does patTemplates buy you beyond that, other than another layer of complexity  ;)

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: any introduction/examples with patTemplates in Joomla 1.1

Post by ianmac » Wed Mar 22, 2006 8:15 pm

I'm working some of the implementation of everything out still, but I would say the biggest advantage would be the ability to reuse custom output elements without having to write library functions.  My hope eventually is to be able to send my variables and have it automatically create an adminlist (a list of records from a table with ordering features and the rest...)

One of the things I'm looking forward to is something that I think is going to be packaged into the Joomla! framework once some of the components are transferred into patTemplates.  That is the ability for users to write alternate templates that override the default ones.  So for example, if a component used a certain template to display its output, I could take that template and modify it, and put the new one in the correct directory.  When Joomla! loaded the core component, it would check for an overriding template first, and if it found it, it would use it.  Otherwise, it would use the default template.

What I also like is the ability to write my output in straight HTML in the template file, and then just feed variables into it.  I find the template file looks a lot cleaner than having the html code in my html.php file.  Just my preference though, I guess.

Ian


Locked

Return to “patTemplate”