Difference between templateValues and templateData
-
Hi!
What's the difference betweentemplateValues
(tV) andtemplateData
(tD)?I know we get tD from a template hook and tV from a header hook, but we also get
data
from 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
data
in 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.renderFooter
is fired, only tV is present and notdata
? -
For the header
data
variable is the data used to render the content of the page and it changes based on which page you are loadingtemplateValues
is passed to the theheader
template 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.renderFooter
hook uses the entire page data to render the footer. So it is different thanfilter:middleware.renderHeader
. I would prefer if they both had the same signature. -
Yeah, I guess my line of thinking is; why not just have
templateValues
andtemplateData
on initial render and thentemplateData
on page render? It just feels a bit confusing with these different signatures and names.So, what is
data
used for when header is rendered? Is it even used? And if not, why not just usetemplateData
on all of them with things related to their function?templateData
on header hook is to render header.
templateData
on page hook is to render page.
templateData
on footer hook is to render footer.I'm guessing there are cases where it's useful for
data
to 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
templateValues
anddata
.templateValues
is used to render header.tpl anddata
is the data used to render that page. If you want to use any variables fromdata
in header.tpl you need to assign them totemplateValues
in 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
templateValues
if 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.