XF 2.2 Is it possible to include variables in a custom template?

Unique Username

Well-known member
Hi all,

I'm trying to add forum stats to my footer (displays post counts, newest member etc) without using a widget. Is it possible to include variables into my custom template?

https://prnt.sc/uuvzn2 - As you can see here, I'm trying to get the post count to display however it is showing up as 0, although its actualy 29.
 
Enter this into the template:
PHP:
{{ dump(vars()) }}

That will allow you to check which variables are available.

More information in this guide:

It;s most likely available using __globals.
 
Enter this into the template:
PHP:
{{ dump(vars()) }}

That will allow you to check which variables are available.

More information in this guide:
Thanks, Brogan, so I have done this. However, it's showing up as NULL. From what I understand, it is only available to certain templates?

I'm trying to use these variables within a template I created called "02_footer".
 
How have you included your custom template?

Into which template?

If it is included in the PAGE_CONTAINER template then there should be vars available.

1602091165538.webp
 
I thought from your first post you wanted the visitor's post count.

Have a look through the available vars to see if there's one for the board total.

I'm with Russ though, I would just use a widget - that's what they're for.
 
Just curious but, why do you want to avoid using a widget if you want to display practically the same info?
I currently trying to learn more about variables, using the widget just bypasses what I'm trying to learn. I'm building a style for my community and wanted to get more of an idea on how to use variables to my advantage. Not saying it's the best way but it's just how I'm trying to learn it.
 
So, in this case the board total isn't available outside the widget template.

I'll do an additional guide for how to get vars from one template in another and update the resource.

If you want to try it in the meantime, add this to the widget_forum_statistics template:
1602099593090.png

You can name ctaTotal to whatever you want but make sure it's unique.

Then you can call the variable in your custom template using:
1602098886082.png

Just make sure you use the same variable name - in this case ctaTotal.

1602098959838.png

1602098950866.png

Edit: And thinking about that, it's likely not going to work on any page where the widget isn't displayed, so in this case, that's not going to help.
 
Last edited:
It would be if it worked ;)

The variable value is only available on a page which the widget is set to display on, so it's not much use if you want to display it in the footer.
 
Worked like a charm! All these work as well!
Code:
{$xf.app.forumStatistics.messages}
{$xf.app.forumStatistics.threads}
{$xf.app.forumStatistics.users}
{$xf.app.forumStatistics.latestUser}
 
Top Bottom