vBulletin Mods

The Official vBulletin Modifications Site
https://www.vbulletin.org/forum/showthread.php?t=188930

Perform simple calculations inside templates!
by Lea Verou
23 Aug 2008 20:53

I was quite excited to find this out!

Have you ever wanted to make a simple calculation for a template, like an addition or subtraction? Personally, I needed this many times and most of them I created a plugin for that. Today I discovered that that is unecessary. You can use the conditional to make simple calculations. For instance, lets suppose you want to display somewhere the userid of the current user, incremented by one. You could do this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

This will display as (given that the userid of the user viewing is 1):
Quote:

The next userid is 2.
Of course the userid example is very simple, just to make you understand what I'm talking about.

Let me know if it helped you! :)

Antivirus 30 Aug 2008 01:19

interesting, thanks!

Kaelon 24 Sep 2008 01:39

Very cool! Thanks, Michelle!

Chunky Monkey 21 Oct 2008 23:38

Is there a way we can use this to generate a random number and then test against it so that something happens only 1/X times?

Lea Verou 21 Oct 2008 23:41

Nope. The functions for random number generation aren't allowed in templates, so you have to use a plugin.

Chunky Monkey 22 Oct 2008 00:33

Thank you, Michelle.

gmert 26 May 2009 07:49

Could I change the numbers by myself ????????
for examble, the number 41, to put the number 88 or number 14 ????







ragtek 26 May 2009 08:09

Quote:

Originally Posted by Michelle (Post 1650030)
Nope. The functions for random number generation aren't allowed in templates, so you have to use a plugin.

Mmaybe you could put it into the $safe_functions variable and use it this way;)

gmert 26 May 2009 08:18

How could i do it ??????

L2V 14 Jul 2009 23:42

Anyone know what kinds of simple calculations can be done using this method?

Lea Verou 15 Jul 2009 00:01

Quote:

Originally Posted by L2V (Post 1848852)
Anyone know what kinds of simple calculations can be done using this method?

Anything that doesn't involve functions or the functions involved are allowed within templates.

xlguy 13 Aug 2009 15:18

Thanks for sharing.

Could you do a multiplication? So

$newfigure = $oldfigure + $oldfigure * 0.15

Any idea?

Lea Verou 13 Aug 2009 15:27

Yes you can.

xlguy 13 Aug 2009 15:33

Thanks, sorry I should have been a bit clearer, what would the syntax be? :)

Lea Verou 13 Aug 2009 17:58


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And after that, use $newfigure normally in your template


All times are GMT. The time now is 12:10.

Powered by vBulletin® Version 3.8.14
Copyright © 2020, MH Sub I, LLC dba vBulletin. All Rights Reserved. vBulletin® is a registered trademark of MH Sub I, LLC
Copyright ©2001 - , vbulletin.org. All rights reserved.