0

Is there a good way to determine which page template was loaded for a given URI? I'd like to be able to use this information from an add-on.

For example, if my root template group is home and the user visits /, I want to see that home/index is being used. If the user visits /foo, does EE expose information about whether it has loaded home/foo or foo/index or something else?

When using Structure, I can check for a global variable named structure:page:template_id, and if that exists, I can easily query for that template. But if Structure isn't in use, I can't find a good way to determine which template is used.

2

You'll have to use another hook, template_fetch_template, and cache the template_id there:

public function template_fetch_template($row)
{
  if ( ! ee()->session->cache('your_extension', 'template_id'))
  {
    ee()->session->set_cache('your_extension', 'template_id', $row['template_id']);
  }
}

public function some_other_hook()
{
  $template_id = ee()->session->cache('your_extension', 'template_id');

  //do stuff here with your template_id
}
| improve this answer | |
2

I literally just saw this plugin on twitter this morning: Template Info, which was originally developed by Leevi Graham for EE1, and then Sean ported to EE2.

Just add one or all of the following tags to your template:

{exp:template_info attribute="template_id"}
{exp:template_info attribute="template_name"}
{exp:template_info attribute="template_group_id"}
{exp:template_info attribute="template_group_name"}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.