I'm considering writing an extension that greatly depends on hooks that are available before and during template parsing. I see in the ExpressionEngine hook documentation that there is a hook called 'template_fetch_template' and its parameter is an array of template data called $row. I can't tell from the documentation exactly what data is in that array. What are the array indexes and what kind of content do they possess?

  • 2
    Whenever exploring an extension hook that receives one or more arguments, I just write a dummy extension that just does this: var_dump($passed_arg); exit();. Commented Nov 30, 2012 at 20:30

1 Answer 1


This is array_keys($row):

    [0] => template_id
    [1] => site_id
    [2] => group_id
    [3] => template_name
    [4] => save_template_file
    [5] => template_type
    [6] => template_data
    [7] => template_notes
    [8] => edit_date
    [9] => last_author_id
    [10] => cache
    [11] => refresh
    [12] => no_auth_bounce
    [13] => enable_http_auth
    [14] => allow_php
    [15] => php_parse_location
    [16] => hits
    [17] => group_name

template_data is probably the most interesting one. It contains the unparsed template code. Note that you cannot change the template code directly (because $row is a copy not a reference), but you can prepend to the $this->EE->config->_global_vars array with a key that consists of a substring from the template code (or indeed, the entire template code could be the key). As the globals array is replaced into the template later on this gives you a mechanism for manipulating the template code before it is parsed.

  • injecting template in globals key, sneaky crox :-) edit: but aren't globals replaced with curly brackets around them? e.g. {keyname} ?
    – GDmac
    Commented Dec 1, 2012 at 11:50
  • 1
    They are indeed so yes the bit you want replaced needs to at least be enclosed by braces {}. I use it for including other templates early on via {stash:embed}. Commented Dec 2, 2012 at 15:15

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.