Page 1 of 1

($tpl); ?

Posted: Tue Aug 14, 2007 7:04 pm
by jalil
i looked quickly through the beginners tutorial and able to understand all of what is being documented directly or by implied reference, except for this....($tpl);

Code: Select all

class HelloViewHello extends JView
{
    function display($tpl = null)
    {
------------------
------------------
------------------
------------------
        parent::display($tpl);
    }
}


$tpl is defined and used and not mentioned at all in the tutorial, leaving poor newbies like me in the dark.

Question : What is $tpl ? what is it used for ? where is it defined ? is there global $tpl?
i the above example taken from the tutorial, $tpl  is defined null and a call to the parent JView is made with a null.
why bother defining it at all then ?

i'm sure there is a good reason to all this. if only it is explained.
thanks.

p/s the tutorials are simple and clear. and have the effect of supressing cryptic Joomla classes and terminologies, but it is perhaps for those who speak PHP only. this is fine as that's the langauge J! is built upon. thank you for this tutorial.

Re: ($tpl); ?

Posted: Tue Aug 14, 2007 8:49 pm
by CirTap
Hi,

jalil wrote:i'm sure there is a good reason to all this. if only it is explained.
thanks.

If you drill down to the JView class you wil find that display() will call loadTemplate($tpl) which will create the filename for the template to load.
This filename is created as
  $file = isset($tpl) ? $this->_layout.'_'.$tpl : $this->_layout;
hence if $tpl happens to be null, the name comes from $this->_layout, otherwise it's appended: $this->_layout.'_'.$tpl

In example for the frontpage you can have a layout called 'default' and it knows two views: 'list' and 'item'.
If one of these view-names is provided the template file becomes 'default_list.php' or 'default_item.php'. These are some sort of "subtemplates" for the "default.php" template.
It's all a matter of names, schemas, and defaults actually ;)

Have fun,
CirTap

Re: ($tpl); ?

Posted: Wed Aug 15, 2007 11:43 am
by jalil
ok, i get it, $tpl=null is actually default, not a permanent assignment !
thanks !

so $this->_layout defaults to index.php of the site template ?
or is this template for displays in contents only ?
meaning to say, we can have our own customised content display ?

i'm a little confused as you can very well see.

Re: ($tpl); ?

Posted: Wed Aug 15, 2007 2:52 pm
by CirTap
Hi,

I admit I have no idea what beginner tutorial you're referring to, so I might repeating things here.

If you don't change anything in the View, $_layout has a value of "default" => default.php in the component's views/xxx/tmpl/ path
'xxx' is derived from the view's classname, i.e. for com_content you can have; archive, article, category, frontpage, and section.
Their view classes are called: ContentViewArchive, ContentViewArchive, etc.

Each view can set a different layout (basically per $task and set by the controller). There are for instance the well known "blog" layouts (blog.php) used for the category or section views of com_content.
A "blog" layout in J! usually consists of the subtemplates blog_item and blog_link, i.e for HTML output:
- view = section ( ~ com_content/views/section/view.html.php)
- _layout = "blog" ( ~ com_content/views/section/tmpl/blog.php

using $view->display( null ) loads "blog.php"
using $view->display( 'item' ) loads "blog_item.php"

Once you code a Controller it (should) assign different views and layouts and call display() as needed for the incoming request.
Easy  8)

Hope this helps.

Have fun,
CirTap

jalil wrote:ok, i get it, $tpl=null is actually default, not a permanent assignment !
thanks !

so $this->_layout defaults to index.php of the site template ?
or is this template for displays in contents only ?
meaning to say, we can have our own customised content display ?

i'm a little confused as you can very well see.


Re: ($tpl); ?

Posted: Wed Aug 15, 2007 3:23 pm
by jalil
CirTap wrote:I admit I have no idea what beginner tutorial you're referring to, so I might repeating things here.

http://dev.joomla.org/component/option, ... omponents/
the ones on MVC.

CirTap wrote:Once you code a Controller it (should) assign different views and layouts and call display() as needed for the incoming request.
Easy  8)
Hope this helps.


Very clear, easy and helpful indeed, thanks, i gonna have fun , yes. It wasn't explained like this in the tutorial, because i think the intended audience are beginners, but then again it does leave some mystery to the beginner to figure out.
One need not bother about all this if the sole purpose is to output 'hello world', but it would be severely limiting i would say.
thanks again.