vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin Tips & Tricks (https://vborg.vbsupport.ru/forumdisplay.php?f=239)
-   -   Perform simple calculations inside templates! (https://vborg.vbsupport.ru/showthread.php?t=188930)

Lea Verou 08-22-2008 10:00 PM

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>
The next userid is $nextid.

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 08-30-2008 12:19 AM

interesting, thanks!

Kaelon 09-24-2008 12:39 AM

Very cool! Thanks, Michelle!

Chunky Monkey 10-21-2008 10:38 PM

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 10-21-2008 10:41 PM

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

Chunky Monkey 10-21-2008 11:33 PM

Thank you, Michelle.

gmert 05-26-2009 06:49 AM

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







ragtek 05-26-2009 07:09 AM

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 05-26-2009 07:18 AM

How could i do it ??????

L2V 07-14-2009 10:42 PM

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


All times are GMT. The time now is 11:28 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
  • Page Generation 0.01003 seconds
  • Memory Usage 1,729KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete