Page 1 of 1

UDT to get root page alias and id, page level, is page root - no sql queries

Posted: Sat May 01, 2010 10:50 am
by vilkis
The UDT gets  root page alias and id, page level and checks if current page is root. After this UDT is called one can use smarty variables
{$root_alias}, {$root_id}, {$is_root}, {$page_level}  in template. This UDT does not use sql queries.

Code: Select all

global $smarty;
$op = $smarty->get_template_vars('content_obj');
$current_id = $smarty->get_template_vars('content_id');
$temp = explode('/', $op->mHierarchyPath);
$root_alias = $temp[0];
$temp = explode('.', $op->mIdHierarchy);
$root_id = $temp[0];
if ($temp[0] == $current_id){
 $is_root = 1;
 $page_level = 1;
}
else{
  $is_root = 0;
  $page_level = array_search($current_id, $temp, true);
  $page_level++;
}
$smarty->assign('root_alias',$root_alias);
$smarty->assign('root_id',$root_id );
$smarty->assign('is_root',$is_root );
$smarty->assign('page_level',$page_level);
return;
vilkis

Re: UDT to get root page alias and id, page level, is page root - no sql queries

Posted: Tue May 04, 2010 9:28 am
by JonathanT
Unfortunately I cannot get this to work. As a quick break down of what I have done,

Created a UDT called {get_root}

Called that Tag in the template.

Called the {$root_alias} in the template.

Unfortunaltly does not display anything. Is there any dependencies?

Re: UDT to get root page alias and id, page level, is page root - no sql queries

Posted: Tue May 04, 2010 9:41 am
by JonathanT
Ok, sorry this does work. However if you are inserting this into your template, it only works for me if you insert it inside the body tag. So if you insert the UDT inside the header in the template it will not work. But if you insert it into the if correctly populates the variables. Weird but it works.

Maybe a V1.1 on the cards?

Thanks again!

Re: UDT to get root page alias and id, page level, is page root - no sql queries

Posted: Tue May 04, 2010 10:34 am
by vilkis
Did you try to insert the UDT on the top of template.

What is value of $config['process_whole_template'] in config.php?

vilkis

EDIT: It works for me in any place of template.

EDIT2: if $config['process_whole_template'] is set to false you have to place the UDT on the top of template otherwise those smarty variables set by UDT will be not available in body tag. This is because in case of $config['process_whole_template'] = false the order of processing of template is the following: top, body, head.

Re: UDT to get root page alias and id, page level, is page root - no sql queries

Posted: Wed May 05, 2010 9:14 am
by JonathanT
It was set to false.

So Ok, you can use the UDT anywhere in the template that you then call the variable. As long as its in the same section.

So if you call the UDT in the body section, you can use the variable in that section.

However IF you want the variable available for the whole template, just call it right at the very top OR if you want to (because you like sticking you UDT's in the header becuase you just like things looking pretty) you would have to change the config.php to process_whole_template = true.

Am I correct in this thinking?

Either way it works so Im chuffed, thank you very much. Keep up the good work.

Re: UDT to get root page alias and id, page level, is page root - no sql queries

Posted: Wed May 05, 2010 10:04 am
by vilkis
JonathanT wrote: Am I correct in this thinking?
yep.

vilkis

Re: UDT to get root page alias and id, page level, is page root - no sql queries

Posted: Sun Oct 24, 2010 2:10 am
by CMSMSrocks!
Thanks!