• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Lack of interest List of variables *used* in a Template

Shadab

Well-known member
#1
I'd love to see a feature (in debug mode only) that would allow developers to check which variables are *used* when rendering a template. This would come in very handy when we want to reuse default xenforo templates in our own applications; so we can easily know the bare minimum data (parameters) required to render a template.

For example, here's a list which could be generated for the "post" template:
Code:
$canReply
$canViewIp
$post
$post.attachments
$post.canCleanSpam
$post.canDelete
$post.canEdit
$post.canInlineMod
$post.canLike
$post.ip_id
$post.like_date
$post.position
$post.post_date
$post.post_id
$post.username
$thread
$visitor.user_id
I know it's almost impossible to list all the variables required for rendering a template; when you take into account template helpers, hooks and nested templates. But listing the immediate variable usage (nested templates not included) would still be nice. :)
 

Shadab

Well-known member
#3
Thanks Jake. (I had even liked the post!)

A lot of times, the variables that a particular template *uses* is actually a small subset of variables *available* to it. Checking the controller which injects the variable parameters, or dumping the data gives us the variable's availability. But the only way to know if that variable is used is to check the template itself; which can be a bit tedious in case of large templates like thread_view & its associated templates.
 

Kier

XenForo Developer
Staff member
#4
We are fairly judicious in our exposure of variables to templates. I would take it that if a variable is exposed via $viewParams in the responseView(), it is required by the template named, or that we intend for it to be used in the future.