($tpl); ?

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
User avatar
jalil
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 128
Joined: Wed Jul 04, 2007 4:54 am
Location: Kuala Lumpur, Malaysia
Contact:

($tpl); ?

Post by jalil » Tue Aug 14, 2007 7:04 pm

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.
Last edited by jalil on Tue Aug 14, 2007 7:17 pm, edited 1 time in total.

User avatar
CirTap
Joomla! Intern
Joomla! Intern
Posts: 73
Joined: Mon Dec 12, 2005 5:34 pm
Contact:

Re: ($tpl); ?

Post by CirTap » Tue Aug 14, 2007 8:49 pm

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
You can have programs written fast, well, and cheap, but you only get to pick 2 ...

"I love deadlines. I like the whooshing sound they make as they fly by." Douglas Adams

User avatar
jalil
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 128
Joined: Wed Jul 04, 2007 4:54 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: ($tpl); ?

Post by jalil » Wed Aug 15, 2007 11:43 am

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.
Last edited by jalil on Wed Aug 15, 2007 12:10 pm, edited 1 time in total.

User avatar
CirTap
Joomla! Intern
Joomla! Intern
Posts: 73
Joined: Mon Dec 12, 2005 5:34 pm
Contact:

Re: ($tpl); ?

Post by CirTap » Wed Aug 15, 2007 2:52 pm

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.

You can have programs written fast, well, and cheap, but you only get to pick 2 ...

"I love deadlines. I like the whooshing sound they make as they fly by." Douglas Adams

User avatar
jalil
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 128
Joined: Wed Jul 04, 2007 4:54 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: ($tpl); ?

Post by jalil » Wed Aug 15, 2007 3:23 pm

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.


Post Reply