LISE and custom field from smarty Topic is solved

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
webform
Power Poster
Power Poster
Posts: 463
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

LISE and custom field from smarty

Post by webform »

I'm trying to have a dropdown in a LISE Instance with categories from another LISE Instance, but i can't seem to figure out if it's possible with field type "Custom field from smarty"?

The help description says:

Code: Select all

{$opts = [1 => 'one', 2 => 'two']}
{html_options options=$opts selected=$sel}
And i tried to change that to:

Code: Select all

{cms_module module='LISEContacts' action='category' assign='opts'}
{html_options options=$opts selected=$sel}
with my category template looking like this:

Code: Select all

{strip}[null => '- None -',
{foreach from=$categories item=category name=cat}
{$category->category_id} => '{$category->name}'{if not $smarty.foreach.cat.last},{/if}
{/foreach}
]{/strip}
I do get an output in the dropdown, but it's all in one line surrounded with a div looking like this:

Code: Select all

<div class="lise-admin-wrapper">[null => '- None -',1 => 'Renewable',2 => 'Buildings',3 => 'Oil & Gas',4 => 'Infrastructure',5 => 'Industry',6 => 'PtX',7 => 'WTG']</div>
So i'm clearly doing something wrong or misunderstanding how to use "Custom field from smarty"?
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1932
Joined: Mon Jan 29, 2007 4:47 pm

Re: LISE and custom field from smarty

Post by Jo Morg »

No, you are misunderstanding smarty... :)
So what you are doing is a text representation of an array, which is not the same as an array.
I would try this:

Code: Select all

{* LISE Categories *}
{$opts [''] =  '- None -'}
{foreach $categories as $category}
  {$opts[{$category->category_id}] =  {$category->name}
{/foreach}
{$opts = $opts scope = parent} {* this line may or may not be needed - test without it 1st *}

Code: Select all

{* LISE custom field from smarty *}
{cms_module module='LISEContacts' action='category'}
{html_options options=$opts selected=$sel}
You may have issues with scope but other than that it should work. The way I posted it is a variable containing an array that you are passing to html_options.

HTH
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
webform
Power Poster
Power Poster
Posts: 463
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: LISE and custom field from smarty

Post by webform »

Thanks a lot for pointing me in the right direction.

Intialy it didn't work because of a" too many shorthand attributes" error. But after searching some more on arrays i came up with a solutions thats working:

Code: Select all

{$cat_ids[] = null}
{$names[] = '- None -'}
{foreach $categories as $category}
{$cat_ids[] = $category->category_id}
{$names[] = $category->name}
{/foreach}
{$cat_ids = $cat_ids scope = parent}
{$names = $names scope = parent}
Scope was important for the next step.
And then in "Custom field from smarty":

Code: Select all

{cms_module module='LISEContacts' action='category'}
{html_options values=$cat_ids output=$names selected=$sel}
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1932
Joined: Mon Jan 29, 2007 4:47 pm

Re: LISE and custom field from smarty

Post by Jo Morg »

webform wrote: Tue Dec 12, 2023 4:46 pm Intialy it didn't work because of a" too many shorthand attributes" error.
Having posted it by memory I suddenly realized there were a few syntax errors but it should have worked with:

Code: Select all

{* LISE Categories *}
{$opts[''] =  '- None -'}
{foreach $categories as $category}
  {$opts[$category->category_id] =  $category->name}
{/foreach}
Last edited by Jo Morg on Wed Dec 13, 2023 1:59 pm, edited 1 time in total.
Reason: Fixed a typo (an extra space) as spotted by webform, thanks
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
webform
Power Poster
Power Poster
Posts: 463
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: LISE and custom field from smarty

Post by webform »

Thanks! It's much shorter and sweeter than my take. ;D

One thing though. The space results in a " too many shorthand attributes" error.:

Code: Select all

{$opts [''] =  '- None -'} change to {$opts[''] =  '- None -'}
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1932
Joined: Mon Jan 29, 2007 4:47 pm

Re: LISE and custom field from smarty

Post by Jo Morg »

Ah! missed that one :D. fixed and thanks!
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
webform
Power Poster
Power Poster
Posts: 463
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: LISE and custom field from smarty

Post by webform »

For future references

LISE Instance Category Template:

Code: Select all

{* LISE Categories *}
{$opts[''] =  '- None -'}
{foreach $categories as $category}
  {$opts[$category->category_id] =  $category->name}
{/foreach}
{$opts = $opts scope = parent}
Other LISE Instance "Add Field Definition => Custom Field From Smarty":

Code: Select all

{cms_module module='LISEmyinstance' action='category'}
{html_options options=$opts selected=$sel}
Post Reply

Return to “Modules/Add-Ons”