![]() |
Perform simple calculations inside templates!
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: HTML Code:
<if condition="$nextid = $bbuserinfo['userid']+1"></if> Quote:
Let me know if it helped you! :) |
interesting, thanks!
|
Very cool! Thanks, Michelle!
|
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?
|
Nope. The functions for random number generation aren't allowed in templates, so you have to use a plugin.
|
Thank you, Michelle.
|
Could I change the numbers by myself ????????
for examble, the number 41, to put the number 88 or number 14 ???? |
Quote:
|
How could i do it ??????
|
Anyone know what kinds of simple calculations can be done using this method?
|
Quote:
|
Thanks for sharing.
Could you do a multiplication? So $newfigure = $oldfigure + $oldfigure * 0.15 Any idea? |
Yes you can.
|
Thanks, sorry I should have been a bit clearer, what would the syntax be? :)
|
Code:
<if condition="$newfigure = $oldfigure + $oldfigure * 0.15"></if> |
What would be the format for:
Displaying the cumulative count of all a users posts ? so if they have 5 threads. thread a has 23 views thread b has 34 views thread 3 has 26 views so on and so on... and create code to echo the total of those views a+b+c etc |
If I understood what you're trying to do correctly, that's not possible in the templates alone.
|
Ok thanks, back to the drawing board.
|
This is a great tip! I've already found a couple of uses for it. :)
|
All times are GMT. The time now is 01:00 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|