PDA

View Full Version : My odd project


darnoldy
01-14-2015, 03:35 AM
Folks-

I'm trying to build something that's not-a-forum using vB3...

On the forum home page, I want to display two less threads than are actually in each forum (a long explanation, that I'm happy to skip).

The template variable, $forum[threadcount], gives me the actual count?but it appears that it is a string, rather than a value.

Is there any way that I can convert the variable to a value, perform an operation on it, convert the result back to a string?within the template?

--don

kh99
01-14-2015, 07:02 PM
I guess it depends on the string format. If it automatically converts to the right integer then you might be able to do it (although I'm not certain offhand), otherwise you'd need to use a plugin.

nerbert
01-14-2015, 08:10 PM
$threadcount = intval($forum[threadcount]);

kh99
01-14-2015, 08:20 PM
$threadcount = intval($forum[threadcount]);

Well, yeah, in a plugin. But you can't put that in a template. Also, if the number is formatted with a thousands separator (like a comma) then that will work until there are more than 1000 threads (I found this out the hard way with user post).

darnoldy
01-15-2015, 03:06 AM
if the number is formatted with a thousands separator (like a comma) then that will work until there are more than 1000 threads (I found this out the hard way with user post).Guess I need to rethink my approach.

nerbert
01-15-2015, 04:29 AM
Well, yeah, in a plugin. But you can't put that in a template. Also, if the number is formatted with a thousands separator (like a comma) then that will work until there are more than 1000 threads (I found this out the hard way with user post).

But HTML doesn't do arithmetic!

Try this plugin for "forumbit_display"



$forum['threadcount'] = vb_number_format(intval($forum['threadcount']) - 2);

kh99
01-15-2015, 05:30 AM
But HTML doesn't do arithmetic!

Well, the OP says "within the template", so I took that to mean without a plugin. HTML can't do math but there are {vb:math ...} and {vb:number ...} template tags for doing simple arithmetic and formatting a number.


Try this plugin for "forumbit_display"



$forum['threadcount'] = vb_number_format(intval($forum['threadcount']) - 2);


If the original value is already formatted with commas then you'd still have the issue I mentioned above.

nerbert
01-15-2015, 12:40 PM
I don't see any practical way to do it in a template. Youre right about commas. This should catch it before it's formatted:

$forum['threadcount'] = vb_number_format(intval($counters["$forum[forumid]"]['threadcount']) - 2);


See line 367 functions_forumlist.php