Could you tell me please, what fetch_template() really means in ExpressionEngine?

Debugger shows me an info like below and not only for ".head" template but for a few more templates.

0.0003s 1.2MB SELECT exp_templates.*, exp_template_groups.group_name FROM (exp_templates) JOIN exp_template_groups ON exp_template_groups.group_id = exp_templates.group_id WHERE exp_template_groups.site_id = '1' AND exp_templates.template_name = '.head' AND exp_template_groups.group_name = 'core'

system/ee/legacy/libraries/Template.php L:216 EE_Template::fetch_template()


2 Answers 2


fetch_template is very important function in ExpressionEngine.

When you browse your EE url in the frontend i.e., http://example.com/about-us, it displays the HTML you saved for that template group.

As you know in EE, all the templates are saved in the Database. You can edit the templates from the backend as well as the frontend.

The fetch_template function works in following manner.

  1. It takes your segments as an argument and triggers the function.
  2. It searches the template in the database that matches with arguments that you have passed in URL i.e., /about-us/(about-us)
  3. If a template is found in the database and there is no file found in FTP, it will return the data found in DB row. (We can save files on FTP by backend settings option Save Templates as Files in template settings)
  4. If a segment is wrong and you have set a 404 page in the backend, it will return data of the 404 row.
  5. If there is a file in the FTP folder and the file edit date is not matched from the DB, it will read the FTP file and return the FTP file content.

The final returned content is filtered by removing EE comments and EE tags are then converted to HTML.

I hope that makes sense. :)


Thanks, everything is clear.

However, debugger mark it as "attention" ("!" sign at 1,2mb) probably because of this operation uses too much of memory. 1,2mb is not too much I think so why it have been marked?


  • Might be because you have lot of templates. It's ok. I don't think you need to worry about this. Commented Feb 22, 2017 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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