PDA

View Full Version : Conditional Templates Hack


dp 
06-28-2001, 02:50 PM
Hi,

maybe you know that problem, just checking if $foo isset, if not dont display option $bar.

this is kinda nasty cuz you gotta edit the .php file and the template.

i've thought about conditional templates and wrote that extremly short hack:

./admin/functions.php

before
if ($gethtmlcomments and $addtemplatename) {

paste this
$template=str_replace('?','"',$template);

this will replace every ?-char with " but it will NOT escape this quote char!

from now on you can use the iif() function:

Template:
... this user has ? . iif($userposts == 1, ?one post?, ?$userpost posts?) . ? since ...

actually it will look like this after beeing parsed:
... this user has " . iif($userposts > 0, "not a single post", "$userpost posts") . " since ...



well thats not easy to explain, i hope you got then point :rolleyes:

note this isnt tested very well, use with care!

mwagstaff
08-15-2002, 12:49 AM
Awesome! This is just what I've been looking for for a long time. Fantastic work! From my quick-and-dirty testing, this appears to be the answer to my conditional templates dreams... :D

Dean C
08-15-2002, 08:17 AM
what is the point of this :S?

mwagstaff
08-15-2002, 11:35 AM
It allows you to include conditional statements in your templates. For example, on my site which is PDA-oriented, I want to display a different layout if a visitor is using a PDA browser (e.g. Pocket Internet Explorer), which obviously has a lot less screen space to play with.

Therefore, I would include a conditional check to see whether a PDA browser is detected or not before deciding which elements of the template to display, and what the layout should be.

Dark_Wizard
08-15-2002, 11:44 AM
Conditional templates will be a feature of vb3....

Boofo
08-15-2002, 11:45 AM
I still don't get it. Any examples of this in use? :)

Originally posted by mwagstaff
It allows you to include conditional statements in your templates. For example, on my site which is PDA-oriented, I want to display a different layout if a visitor is using a PDA browser (e.g. Pocket Internet Explorer), which obviously has a lot less screen space to play with.

Therefore, I would include a conditional check to see whether a PDA browser is detected or not before deciding which elements of the template to display, and what the layout should be.

mwagstaff
08-15-2002, 11:53 AM
I'm still checking, but it appears that the conditional check doesn't work correctly in the postbit templates - the result always comes up as false. :(

mwagstaff
08-20-2002, 12:50 AM
Anyone know what's so special about the postbit templates that they set all variables to null?

For example, if I set a variable $mobile to 1, it will be recognised as such in the showthread template. In the postbit template, however, it always comes up as null (even if I include a php file in the postbit template that specifically sets it to 1).

Entourage
08-22-2002, 04:20 PM
Originally posted by mwagstaff
Anyone know what's so special about the postbit templates that they set all variables to null?

For example, if I set a variable $mobile to 1, it will be recognised as such in the showthread template. In the postbit template, however, it always comes up as null (even if I include a php file in the postbit template that specifically sets it to 1).

Yes the variables are shipped to another php file (postbit is parsed in /admin/functions.php)

Xenon
08-22-2002, 05:15 PM
it's because getpostbit is a real function, so it doesn't use variables from showthread.php
you have to globalize your variable first ;)