[solved] ListIt2 - get options for field definition

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

[solved] ListIt2 - get options for field definition

Post by Cerulean »

I'd like to be able to get the array of options that exist for a specific field definition (e.g. the list of options that are defined for a dropdown control).

I can do that fine if going via a ListIt2 item - I can load an item with ListIt2Loader or in a foreach loop and do:

Code: Select all

$item->fielddefs.myfield->GetOptions()
The problem is that this relies on an item being available. What if my foreach loop returns no items, or the item I try and load with ListIt2Loader has been deleted? I should be able to get the list of options for a field definition even if there are no items existing, because the options exist independent of any items. Does anyone know how to access the list of options without having to load an item?
Last edited by Cerulean on Wed Nov 26, 2014 3:42 am, edited 1 time in total.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: ListIt2 - get options for field definition

Post by psy »

Try

Code: Select all

$item_obj = $mod->LoadItemByIdentifier('item_id', '')
This is the code used to add/edit an item. Before the item is saved there is no item_id so it returns an empty object. You can then use $item_obj to retrieve the field options.

Code: Select all

$item_obj->fielddefs.myfield->GetOptions()
This assumes the $mod is the same as the LI2 instance module of your template.
To retrieve the options from another LI2 instance, use a UDT, eg called 'get_options':

Code: Select all

$field_id=$params['field_id'];
$instance = cms_utils::get_module('myli2instance');
$item_obj=$instance->LoadItemByIdentifier('item_id', '');
$options=$item_obj->fielddefs[$field_id]->GetOptions();
$smarty->assign('options',$options);
and in your template {get_options field_id=7} (or whatever the field id number is). Then use $options in your template.
Last edited by psy on Wed Nov 26, 2014 3:52 am, edited 1 time in total.
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

Re: ListIt2 - get options for field definition

Post by Cerulean »

That is brilliant!
Thanks.
Post Reply

Return to “Modules/Add-Ons”