Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Rounding a template var.
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #15
RE: Rounding a template var.
Oh, I forgot, array_filter doesn't work in Template Conditionals - it's disabled because it can be used to make arbitrary callbacks.

You could either enable it in phptpl_allowed_funcs.txt and take the security risk, or implement your own version of it by adding the following to inc/functions.php

PHP Code:
function array_filter_blank($array) { return array_filter($array); }

and adding array_filter_blank to phptpl_allowed_funcs.txt, then using array_filter_blank instead of array_filter


Also, why are you using "['value']" ?  It should work without that.  intval doesn't seem necessary - this works for me:

Code:
<setvar myratings>array_filter(array($threadfields['pfrating1'], $threadfields['pfrating12']))</setvar>
Average: <?=count($tplvars['myratings']) ? array_sum($tplvars['myratings']) / count($tplvars['myratings']) : 0 ?>


My Blog
05-13-2013 02:11 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
Rounding a template var. - leefish - 04-21-2013, 04:42 AM
RE: Rounding a template var. - ZiNgA BuRgA - 04-21-2013, 04:58 PM
RE: Rounding a template var. - leefish - 04-21-2013, 06:17 PM
RE: Rounding a template var. - ZiNgA BuRgA - 04-21-2013, 07:30 PM
RE: Rounding a template var. - leefish - 04-21-2013, 08:19 PM
RE: Rounding a template var. - ZiNgA BuRgA - 04-21-2013, 09:39 PM
RE: Rounding a template var. - leefish - 04-21-2013, 09:47 PM
RE: Rounding a template var. - leefish - 05-05-2013, 02:20 AM
RE: Rounding a template var. - ZiNgA BuRgA - 05-05-2013, 10:09 PM
RE: Rounding a template var. - leefish - 05-10-2013, 02:36 AM
RE: Rounding a template var. - ZiNgA BuRgA - 05-10-2013, 09:37 AM
RE: Rounding a template var. - leefish - 05-10-2013, 06:04 PM
RE: Rounding a template var. - ZiNgA BuRgA - 05-12-2013, 11:04 AM
RE: Rounding a template var. - leefish - 05-12-2013, 11:48 PM
RE: Rounding a template var. - ZiNgA BuRgA - 05-13-2013 02:11 PM
RE: Rounding a template var. - leefish - 05-13-2013, 09:25 PM
RE: Rounding a template var. - ZiNgA BuRgA - 05-14-2013, 09:34 AM
RE: Rounding a template var. - leefish - 05-14-2013, 06:48 PM

 Standard Tools
Forum Jump: