6

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();. – Derek Hogue Nov 30 '12 at 20:30
8

This is array_keys($row):

Array
(
    [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 Dec 1 '12 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}. – Mark Croxton Dec 2 '12 at 15:15

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.