Using IF Logic and Settings in a Template
Posted by schwing
Using IF Logic and Settings in a Template January 08, 2007 01:44PM |
Registered: 16 years ago Posts: 13 |
I am creating a simple module that will display a form field, or not, based on a settings file managed from the modules page in admin. Basically an on/off toggle of a form field. I would like to be able to test if this setting has been set and only display it's associated form field if it has been set.
If I look at register.tpl I see a block that looks like:
{IF ERROR}
<div class="PhorumUserError">{ERROR}</div>
{/IF}
I would like to do something like this (pseudo-code):
{IF my_mod form field is true}
{HOOK tpl_my_mod_field_hook}
{/IF}
I've tried different variations of the above but am obvious not understanding something.
What is the correct way to check if the value has been set in a template and display my field?
Thanks!
-ken
If I look at register.tpl I see a block that looks like:
{IF ERROR}
<div class="PhorumUserError">{ERROR}</div>
{/IF}
I would like to do something like this (pseudo-code):
{IF my_mod form field is true}
{HOOK tpl_my_mod_field_hook}
{/IF}
I've tried different variations of the above but am obvious not understanding something.
What is the correct way to check if the value has been set in a template and display my field?
Thanks!
-ken
Re: Using IF Logic and Settings in a Template January 08, 2007 02:23PM |
Admin Registered: 20 years ago Posts: 9,240 |
January 08, 2007 03:27PM |
Admin Registered: 19 years ago Posts: 8,532 |
You can only use the {IF ...} .. {/IF} syntax in case the variable that you check is in $PHORUM["DATA"]. If you are using the standard way for storing module settings (using the phorum_db_update_settings() function), then the settings will be in $PHORUM["mod_yourmod"] and $PHORUM["SETTINGS"]["mod_yourmod"] though. As a result of this, you cannot access the setting within an {IF ...} statement.
There are two things you can do.
1) revert to plain PHP code in the template:
Template code:
2) transfer the setting to $PHORUM["DATA"] from a hook in your module.
Module code:
Maurice Makaay
Phorum Development Team
my blog
linkedin profile
secret sauce
There are two things you can do.
1) revert to plain PHP code in the template:
Template code:
<?php
if (isset($PHORUM["mod_yourmod"]["some_setting"]) &&
$PHORUM["mod_my_mod"]["show_form_field"] == true) {
?>
FORM FIELD CODE GOES HERE
<?php
}
?>
2) transfer the setting to $PHORUM["DATA"] from a hook in your module.
Module code:
global $PHORUM; $PHORUM["DATA"]["my_mod_field"] = $PHORUM["mod_my_mod"]["show_form_field"];Template code:
{IF my_mod_field}
FORM FIELD CODE GOES HERE
{/IF}
Maurice Makaay
Phorum Development Team



Sorry, only registered users may post in this forum.