XF 2.2 Sidebar widget Display Condition $xf.vars.posts.count() causing template errors after upgrade from 2.1

Stuart Wright

Well-known member
This isn't a bug as such, but a heads up.
Running 2.2 Beta 4 on our sandbox.
Because I only want to display sidebar widgets on thread_view when there are enough posts to warrant it (I don't want lots of widgets to make the page ugly by creating an overly tall sidebar), I use the Display Condition for 5 out of 6 widgets on the Thread View page.
They all use the $xf.vars.posts.count() conditional.
e.g. $xf.vars.posts.count() > 14
After upgrading, I get 5 template errors when viewing a thread.

My coder John says it's because $xf.vars.posts is now an array instead of an object and we need to use count($xf.vars.posts) instead.
Anyone using $xf.vars.posts.count() in their widget display conditions is going to get the same template error after upgrading, presumably?

This is going to add some time on to the upgrade because we have a few sidebar widgets using this conditional.
So to quickly fix the issue, I've run this query on our sandbox:
Code:
UPDATE xf_widget SET display_condition = REPLACE(display_condition,'$xf.vars.posts.count()','count($xf.vars.posts)');
Which will then require a rebuild of the master data to refresh the cache (unless there is a better way to do it?) and so I'll do it before we run the main upgrade from 2.1 to 2.2.
 
Top