Hi Guys, I wanted to use this for my module but found that asking the user to then upload files around other modules so that my module would work seemed messy and prone to error. So I made some changes that I would like you to include into this module. The changes allow other modules to actually specify a custom template_path and template to use for a custom field. It only requires modifying one file, but then allows other modules to define their own custom templates for custom profile fields.
at line 105 in profile_center_fields.tpl add the following code:
Code:
{*================================*}
{* Custom to see if a custom template has been added to the field and load the related template *}
{* Also checks to see if a custom template_path has been specified for the template *}
{*================================*}
{elseif $users_extra_fields_field[fields].template neq ''}
{if $users_extra_fields_field[fields].template_path neq '' }
{include file=$users_extra_fields_field[fields].template_path.'profile_extend_'.$users_extra_fields_field[fields].template.'.tpl' users_extra_fields_field[fields]=$users_extra_fields_field[fields] field=$users_extra_fields_field[fields]}
{else}
{include file=$users_extra_fields_tpl_path.'profile_extend_'.$users_extra_fields_field[fields].template.'.tpl' users_extra_fields_field[fields]=$users_extra_fields_field[fields] field=$users_extra_fields_field[fields]}
{/if} This allows me to call either templates in the module/users_extra_fields/templates folder or templates defined in my own custom folder. The reason why i pass both the field and users_extra_fields_field[fields] to the template is so that it doesnt break any of your existing templates should i wish to call them via this method.
Then I can leverage this code from my own module by doing the following:
1: I define my custom field in mymodule_install.php exactly the same as before, eg:
Code:
$module_info['db_add_field'][]=array('users', ''my_foo_field', 'TINYINT', 1, "UNSIGNED", 0, '1'); 2: Then in my own mymodule_settings.php file I add the following code just as before, however notice the two new fields template and template_path
Code:
define("mymodule_user_fields_templates_path", "../modules/mymodule/user_fields_templates/");
$users_extra_fields_field[]=array(
'name' => 'my_foo_field',
'show_to_user_text' => 'Do you want to enable foo?',
'show_to_user' => true,
'show_to_admin' => false,
'editby_user' => true,
'editby_admin' => true,
'template' => 'yes_no',
'template_path' => mymodule_user_fields_templates_path,
); 3: The last part to this is of course to add my own custom template for a field to display on the user profile page. So in the modules/mymodule/user_fields_templates/ directory I define my own field template: profile_extended_yes_no.tpl
Code:
{*================================*}
{* Custom user field that shows a 1 as Yes and either a 0 or anything else as No *}
{*================================*}
<td>
<select name="{$field.name}" id="{$field.name}">
{if $field.value eq "1"}
<option value='1' selected="selected">Yes</option>
<option value='0'>No</option>
{else}
<option value='1'>Yes</option>
<option value='0' selected="selected">No</option>
{/if}
</select>
</td>
What do you think? cool??? It definitely seems better to allow other modules to create custom fields without the user having to copy and modify files in other modules. I have attached a copy of the profile_center_fields.tpl file.
cheers.