Joomlart T3 framework Insight & Gavick Pro Template

本文深入探讨了T3框架下模板结构的组织方式,解释了入口点index.php的作用以及如何通过调用display()函数输出HTML内容。详细分析了布局文件layout.php内的逻辑流程,特别是如何加载不同的块(block)并使用Joomla模板全局信息协同工作。同时,介绍了T3框架中块的概念,以及如何通过位置(position)数组将Joomla模块放置于特定块内,实现高度灵活性的页面构建。

T3 framework file structure & what are they doing


Since I can't get support from Gavick Pro-you can't post in their forum unless you pay money for that, then I will have to figure out the logic of the program and the organization of files.


So let's roll off...........


The entry point of this template is still index.php under \templates\gk_sporter\ directory, and for now, even I don't understand all the PHP code inside it, but we can say that the main point that initiate the process of outputting HTML is the call to display():


$layout = $tmpl->getLayout();

if ($layout)
{
	$tmpl->display($layout);
}


And the variable $tmpl is an instance of GKTemplateHelper, from the first few lines of code:


include_once (dirname(__FILE__).DS.'libs'.DS.'gk.template.helper.php');

$tmpl = GKTemplateHelper::getInstance($this, array('ui', GK_TOOL_SCREEN, GK_TOOL_MENU, 'main_layout', 'direction'));

So we go to gk.template.help.php, to dig the logics behind out, and here is the function call flow:


display-call-flow


At the moment, I am just curious about the content held by $layoutpath, so add code

dump( $layoutpath, 'layoutpath' );

into the function body, but before that make sure you have JDump plug-in installed. And the result goes:


jdump-layoutpath


Actually, that output is produced by multiple calls to the function_load(). Why is that? Just comment out the include directive:


	function _load ($layout)
	{
		if (($layoutpath = $this->layout_exists ($layout)))
		{
			//dump( $layoutpath, 'layoutpath' );
			var_dump($layoutpath);
			//include ($layoutpath);
		}
	}

then the output is only one line:

string(64) "C:\xampp\htdocs\joomla!\templates\gk_sporter\layouts\default.php"


it is because inside  gk_sporter\layouts\default.php, there are many calls like: 

$this->loadBlock('head');

and that will result in the include statements be executed again and again, here is the call flow:


include-call-flow 

And that explains how T3 framework assembly different blocks, and take a look at blocks\head.php:

<?php if($this->_tpl->params->get("chrome_frame")) : ?>
<meta http-equiv="X-UA-Compatible" content="chrome=1"/>
<?php endif; ?>

<jdoc:include type="head" />
<?php JHTML::_('behavior.mootools'); ?>

<?php if (!$this->isIE6()) : ?>

<?php
	
	$document =& JFactory::getDocument();
	$headData = $document->getHeadData();
	$scripts_array_keys = array_keys($headData['scripts']);
	$headData['scripts'] = array();
	foreach($scripts_array_keys as $key){
		$headData['scripts'][$key] = 'text/javascript';
		if(preg_match('/mootools.js/',$key)) {
			$headData['scripts'][$this->templateurl().'/js/domready_fix.js'] = 'text/javascript';
		}
	}

......

there is one Joomla! function, which is <jdoc:include type="head" />, that shows how T3 and Joomla! cooperate together.  In the above piece, the head block still uses Joomla! template's global information to faciliate the loading of the head part of an HTML page, such as javascript, CSS and so on........


Apart from that, inside the block, there are calls that specific to the template:


......
<?php if (($gkmenu = $this->loadMenu())) $gkmenu->genMenuHead (); ?>
<?php $this->loadBlock('cufon'); ?>
......

and it may load other block files. So that is why I said the output by JDump is due to mutiple calls of_load(). By adding the express

var_dump($layoutpath);

before

include ($layoutpath);

we can get an output that shows up the block file's path immediate above its content, and eventually the output html block is sliced up by the string generated by var_dump() function, that providing much convenience for further study.


Block in T3 framework & how block works


In T3, block is one brand-new concept introduced----to provide higher flexiblity.Blocks are similar to positions in Joomla!, but they are at different hierarchical level, in terms of capacities of accommodating HTML output. All T3 templates are cut up into blocks, one block can contain other blocks, or just contain positions of Joomla!, the following is the default structure of the template based on T3 framework.


t3-default-layout


and the following is sporter template's layout(from help document): 


sporter-position


At this point, we come to the problem, that is how do this two layouts work together, or say what is the relationship between them? In gk_sporter\layouts\default.php, this file contains this piece of code: 

$positions = array (
	'left1'					=>'left1',
	'left2'					=>'left2',
	'left-mass-top'			=>'left_top',
	'left-mass-bottom'		=>'left_bottom',
	'right1'				=>'right1',
	'right2'				=>'right2',
	'right-mass-top'		=>'right_top',
	'right-mass-bottom'		=>'right_bottom',
	'content-mass-top'		=>'top',
	'content-mass-bottom'	=>'bottom',
	'content-top'			=>'adv_top',
	'content-bottom'		=>'adv_bottom',
	'inset1'				=>'inset1',
	'inset2'				=>'inset2'
);

this snippet declares an array named $position, and assigns it to some position names, actually, the keys of array are block names in T3 template, and the values are position names in Joomla!. This array is used to keep track of which position modules in Joomla! do you want to put on each block in T3 template. As shown:


block-position


Please note that, althought the $position defines all the blocks shown in T3 default template, it only includes the positions of Sporter partially( the ones embraced in MAIN square in the following figure ). And now, let's map the positions in sporter template to the blocks in T3, indeed the block's name is refered as the php files(for example, to load top block will actually include top.php):


map-position-to-block-file


And take nav.php as example, open it in easyEclipse to inspect how it include the positions:breadcrumb,top_nav,menu and highlighter.


nav-load-pos


In summary, you can change the $position array its element values, to change the position of the modules, or you can even rearrange the php statement of loading blocks if you like, but that should not be the original aim of T3 developers.




A blog:


http://viiiix.com/joomla-documentation/ja-template-framework-guides


A forum:


http://www.joomlagate.com/forum/








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值