XF 2.2 User reaction_ratio

Nicolas FR

Well-known member
Hello,
Is there a way to display a user's reaction_ratio?
Tried {$xf.visitor.reaction_ratio} or {$user.reaction_ratio} without success.
Thanks.
 
Solution
{{ number($user.reaction_score/$user.message_count, 2) }}

The second argument denotes the number of decimal places.

You can also do: {{ ($user.reaction_score/$user.message_count)|number }} -- that would round to whole numbers.

This would give 2 decimal places: {{ ($user.reaction_score/$user.message_count)|number(2) }}

You likely want to be using $user rather than $visitor.
The former is the account the function is being applied to, the latter is the account viewing the page.
Nope, ratio. reaction/posts
HTML:
<xf:option name="user_criteria[reaction_ratio][rule]" value="reaction_ratio" selected="{$criteria.reaction_ratio}"
    label="{{ phrase('user_reaction_message_ratio_is_at_least:') }}">
    <xf:numberbox name="user_criteria[reaction_ratio][data][ratio]" value="{$criteria.reaction_ratio.ratio}"
        size="5" min="0" step="0.25" />
    <xf:afterhint>{{ phrase('reaction_message_ratio_explanation') }}</xf:afterhint>
</xf:option>

This is part of the criteria for promoting user groups and I would like to display the one for users but it seems complicated I do not see this value anywhere If i dump vars
 
Can i make maths operations in HTML ? :D

Something like ?
Code:
{$xf.visitor.reaction_score} / {$xf.visitor.message_count} = ($value}

OR

{$xf.visitor.reaction_score|number} / {$xf.visitor.message_count|number} = ($value}
 
{{ number($user.reaction_score/$user.message_count, 2) }}

The second argument denotes the number of decimal places.

You can also do: {{ ($user.reaction_score/$user.message_count)|number }} -- that would round to whole numbers.

This would give 2 decimal places: {{ ($user.reaction_score/$user.message_count)|number(2) }}

You likely want to be using $user rather than $visitor.
The former is the account the function is being applied to, the latter is the account viewing the page.
 
Solution
In case you are interested (you seem to be getting into developy stuff), using number($var) is a function, using $var|number is a filter.

They can also be used together, like so: {{ function($var)|filter}}.

All of the them can be found in src/XF/Template/Templater.php.

These are all the filters:
Code:
default
censor
count
currency
emoji
escape
for_attr
file_size
first
format
hex
host
htmlspecialchars
ip
join
json
last
nl2br
nl2nl
number
number_short
numeric_keys_only
pad
parens
pluck
preescaped
raw
replace
split
split_long
strip_tags
to_lower
to_upper
de_camel
substr
url
urlencode
zerofill

These are all the functions:
Code:
anchor_target
array_keys
array_merge
array_values
asset
attributes
avatar
base_url
bb_code
bb_code_snippet
bb_code_type
bb_code_type_snippet
button_icon
cache_key
call_macro
callable
captcha
ceil
contains
copyright
core_js
count
csrf_input
csrf_token
css_url
date
date_from_format
date_dynamic
date_time
debug_url
display_totals
dump
dump_simple
duration
empty
fa_weight
file_size
floor
gravatar_url
highlight
in_array
is_array
is_scalar
is_addon_active
is_editor_capable
is_toggled
js_url
key_exists
last_pages
likes
likes_content
link
link_type
min
max
max_length
media_sites
mustache
number
number_short
named_colors
page_description
page_h1
page_nav
page_param
page_title
parens
parse_less_color
phrase_dynamic
prefix
prefix_group
prefix_title
prefix_description
prefix_usage_help
profile_banner
property
rand
range
react
alert_reaction
reaction
reaction_title
reactions
reactions_content
reactions_summary
redirect_input
repeat
repeat_raw
short_to_emoji
show_ignored
smilie
snippet
strlen
structured_text
templater
time
transparent_img
trim
unique_id
user_activity
user_banners
user_blurb
user_title
username_link
username_link_email
widget_data


Maybe I'll do a guide resource for this stuff one day ...
 
Maybe I'll do a guide resource for this stuff one day ...
That would be cool, the developer doc is well done but there is so much missing information like this for example (or maybe I missed it?).

I understand more or less what I can do with these functions and filters but I must admit that I cannot give a precise definition of them, these are new terms that I am discovering and I do not always understand their true meaning.

(you seem to be getting into developy stuff)
Yes and I'm really having fun! It's so satisfying to come face to face with problems and find their solutions. I created my first widget definitions this afternoon and I had to analyze, copy, paste, delete, test, recopy, paste pieces of PHP code until I understood how it worked, when my first widget is displayed correctly on my dev forum it was really satisfying!

-----

BTW using {{ number($user.reaction_score/$user.message_count, 2) }} and {{ ($user.reaction_score/$user.message_count)|number }} returns the error

Template Compilation Error​

public:_widget_ratio - Division by zero in C:\laragon\www\internal_data\code_cache\templates\l3\s1\public\_widget_ratio.php:7

But works fine using $xf.visitor instead of $user
 
Top Bottom