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

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
vilkis

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

Post 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
JonathanT
New Member
New Member
Posts: 4
Joined: Tue May 04, 2010 9:15 am

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

Post 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?
Last edited by JonathanT on Tue May 04, 2010 9:30 am, edited 1 time in total.
JonathanT
New Member
New Member
Posts: 4
Joined: Tue May 04, 2010 9:15 am

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

Post 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!
vilkis

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

Post 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.
Last edited by vilkis on Tue May 04, 2010 11:32 am, edited 1 time in total.
JonathanT
New Member
New Member
Posts: 4
Joined: Tue May 04, 2010 9:15 am

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

Post 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.
vilkis

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

Post by vilkis »

JonathanT wrote: Am I correct in this thinking?
yep.

vilkis
CMSMSrocks!
New Member
New Member
Posts: 5
Joined: Fri Oct 22, 2010 8:22 pm

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

Post by CMSMSrocks! »

Thanks!
Post Reply

Return to “Tips and Tricks”