Post by Elli on Aug 16, 2019 12:50:53 GMT -7
Total Stats
Preview
Adds up numbers from custom Mini Profile fields to create a total.
Bottom of Thread and Show Conversation Templates
Example Mini Profile Template
Bottom of Thread and Show Conversation Templates
<script>
$(function() {
// Calculate Mini Profile total stats
(function calcTotal() {
$('.mini-profile').each(function() {
var resultsArr = [];
var $statVal = $(this).find('.custom-stat > .value');
var $totalVal = $(this).find('[data-total="value"]');
$statVal.each(function() {
var num = parseFloat($(this).text());
if (!isNaN(num)) {
resultsArr.push(num);
}
});
var totalNum = resultsArr.reduce(function(a, b) {
return a + b;
}, 0);
$totalVal.append(totalNum);
});
})();
});
</script>
Example Mini Profile Template
<div class="$[miniprofile_class]">
...
{if $[user.is_member]}
<div class="info">
{foreach $[user.mini_custom_field]}
{if $[user.mini_custom_field.name] === "Field 1" || $[user.mini_custom_field.name] === "Field 2"}
<div class="custom-stat">
<span class="name">$[user.mini_custom_field.name]:</span>
<span class="value">$[user.mini_custom_field.value]</span>
</div>
{/if}
{/foreach}
<div class="custom-stat">
<span class="name">Total Stats:</span>
<span class="value" data-total="value"></span>
</div>
</div>
{/if}
</div>