Difference between templateValues and templateData
What's the difference between
I know we get tD from a template hook and tV from a header hook, but we also get
datafrom the header hook, which contains the dame data as in tD?
Hook data object keys in the two cases:
[ 'req', 'res', 'templateValues', 'data' ]from header hook.
[ 'req', 'res', 'templateData' ]from template hook.
So this might not be a technical question at all. I'm just wondering what the naming is meant to be. Maybe someone can shed some light on this, perhaps simple question?
For instance, if
datain header hook is the same as tD in template hook, why is it not just called templateData instead, to avoid confusion?
I guess a header hook is only fired on initial render and not when the user navigates around, as is the case with a template hook.
Also, when for
filter:middleware.renderFooteris fired, only tV is present and not
For the header
datavariable is the data used to render the content of the page and it changes based on which page you are loading
templateValuesis passed to the the
headertemplate to render the header.
Header and footer hooks are only fired once on initial page load.
I think the name was just arbitrary when these hooks were added long time ago. And looks like the
filter:middleware.renderFooterhook uses the entire page data to render the footer. So it is different than
filter:middleware.renderHeader. I would prefer if they both had the same signature.
Yeah, I guess my line of thinking is; why not just have
templateDataon initial render and then
templateDataon page render? It just feels a bit confusing with these different signatures and names.
So, what is
dataused for when header is rendered? Is it even used? And if not, why not just use
templateDataon all of them with things related to their function?
templateDataon header hook is to render header.
templateDataon page hook is to render page.
templateDataon footer hook is to render footer.
I'm guessing there are cases where it's useful for
datato be passed along the ride, but they're already treated as different parts, so maybe it's just easier to separate them entirely.
Right now the header hook is passed two variables
templateValuesis used to render header.tpl and
datais the data used to render that page. If you want to use any variables from
datain header.tpl you need to assign them to
templateValuesin your plugin.
Seems like footer hook is using the entire data object from the page so it can use anything from the page.
Changing the variable name is fine but it would be a breaking change that would break plugins using
templateValuesif we remove it.
Yep, I see the issue. I'm not looking to push any changes. It was more out of curiosity on why there are several different names within essentially the same function.