Jeff VIP
Total posts: 745
01 Dec 2015 03:44

Hi,

I would like to be able to use a field key instead of a field id in order to render an individual field. Cobalt's API only allows field id's, so you can't render a common field from different types dynamically.

In my application, people are able to prolong articles belonging to different types. I would like to show the record's image when they coose a plan. I make use of a cookie to store the record id in order to render it's image on the em_list page. Unfortunately, I can only show images of one type.

I suggest extending Cobalt's API to support field keys or provide me with another solution (please).

Best regards, Jeff

Last Modified: 01 Jun 2016


Sergey
Total posts: 13,748
07 Dec 2015 14:25

Jeff I would like to be able to use a field key instead of a field id in order to render an individual field. Cobalt's API only allows field id's, so you can't render a common field from different types dynamically.

Why? You can use $item->fields_by_key to render field by key.


Jeff VIP
Total posts: 745
07 Dec 2015 22:19

Sergey Why? You can use $item->fields_by_key to render field by key.

I know, but somehow I can't do what I want in my emlist template.

The code I am using in a custom emlist template is

$recnr = $_COOKIE["remember_record_id"];
$record = ItemsStore::getRecord($recnr);
echo CobaltApi::renderField($record, '1', 'full');

The code works just for one content type, because the renderfield Api accepts only field_id. :-(


Sergey
Total posts: 13,748
08 Dec 2015 04:08

I added new parameter for renderField it is $bykey flag which is FALSE by deafult. So you can call it like this.

echo CobaltApi::renderField($record, '1', 'full', '', TRUE);

Sackgesicht VIP
Total posts: 1,636
08 Dec 2015 04:32

Sergey
Total posts: 13,748
09 Dec 2015 03:18

Updated. Thank you for remind me.


Jeff VIP
Total posts: 745
09 Dec 2015 07:13

Sergey echo CobaltApi::renderField($record, '1', 'full', '', TRUE);

You mean:

echo CobaltApi::renderField($record, '$key', 'full', '', TRUE);

Thanks, Sergey!


Sergey
Total posts: 13,748
10 Dec 2015 04:45

Yes key but either this

echo CobaltApi::renderField($record, $key, 'full', '', TRUE);

or this

echo CobaltApi::renderField($record, "$key", 'full', '', TRUE);

but not in single quotes '$key'. It will not work.


Jeff VIP
Total posts: 745
10 Dec 2015 21:55

Sergey but not in single quotes '$key'. It will not work

oooh, that's an important note...

Powered by Cobalt