0

Using joomla! 3.9.2

I have an article custom field, type List with the ID 14. The List values are below:

list values

Text - Value

1 = 335,538,353,559

2 = 390,538,408,559

I am trying to pull the Value of the option 1 into a custom blog_item.php template.

I have had success getting the text value with:

<?php echo $this->item->jcfields['14']->value; ?> 

If I try to get the rawvalue the output is Array.

If the custom field in the the article has 1 selected in the dropdown select how can I output the value 335,538,353,559 ?

-

<?php var_dump($this->item->jcfields['14']); ?> 

=

object(stdClass)#1724 (32) { ["id"]=> string(2) "14" ["title"]=> string(18) "Select Desk Number" ["name"]=> string(16) "selectdesknumber" ["checked_out"]=> string(3) "465" ["checked_out_time"]=> string(19) "2019-02-01 14:02:34" ["note"]=> string(0) "" ["state"]=> string(1) "1" ["access"]=> string(1) "1" ["created_time"]=> string(19) "2019-01-24 08:13:33" ["created_user_id"]=> string(3) "465" ["ordering"]=> string(1) "0" ["language"]=> string(1) "*" ["fieldparams"]=> object(Joomla\Registry\Registry)#1644 (3) { ["data":protected]=> object(stdClass)#1647 (2) { ["multiple"]=> string(0) "" ["options"]=> object(stdClass)#1649 (2) { ["options0"]=> object(stdClass)#1648 (2) { ["name"]=> string(1) "1" ["value"]=> string(15) "335,538,353,559" } ["options1"]=> object(stdClass)#1650 (2) { ["name"]=> string(1) "2" ["value"]=> string(15) "390,538,408,559" } } } ["initialized":protected]=> bool(true) ["separator"]=> string(1) "." } ["params"]=> object(Joomla\Registry\Registry)#1646 (3) { ["data":protected]=> object(stdClass)#1652 (9) { ["class"]=> string(0) "" ["label_class"]=> string(0) "" ["show_on"]=> string(0) "" ["render_class"]=> string(0) "" ["showlabel"]=> string(1) "1" ["label_render_class"]=> string(0) "" ["display"]=> string(1) "0" ["layout"]=> string(0) "" ["display_readonly"]=> string(1) "2" } ["initialized":protected]=> bool(true) ["separator"]=> string(1) "." } ["type"]=> string(4) "list" ["default_value"]=> string(0) "" ["context"]=> string(19) "com_content.article" ["group_id"]=> string(1) "4" ["label"]=> string(18) "Select Desk Number" ["description"]=> string(0) "" ["required"]=> string(1) "0" ["language_title"]=> NULL ["language_image"]=> NULL ["editor"]=> string(13) "Authorname" ["access_level"]=> string(6) "Public" ["author_name"]=> string(13) "Authorname" ["group_title"]=> string(22) "Floor Plan - 3rd Floor" ["group_access"]=> string(1) "1" ["group_state"]=> string(1) "1" ["group_note"]=> string(0) "" ["value"]=> string(1) "1" ["rawvalue"]=> array(1) { [0]=> string(15) "335,538,353,559" } } 

*updated to show jcfields instead of jcFields.

2
  • Welcome to JSE. Can you add var_dump($item->jcFields['14']); and add the result to your original question please? Commented Feb 1, 2019 at 14:48
  • Thanks lodder, please note, the $this as I missed that in my initial question as it is a blog_item.php Commented Feb 1, 2019 at 15:20

1 Answer 1

2

List custom field stores the value as an array to support multiple values. Access the first element of rawvalue to get the value you expect:

<?php echo $item->jcfields['14']->rawvalue[0]; ?> 

Or use implode() to display all values, in case the field has multiple values enabled:

<?php echo implode('|', $item->jcfields['14']->rawvalue); ?> 

Or run a loop to show each value individually:

<?php foreach ($item->jcfields['14']->rawvalue as $value) : ?> <?php echo $value . '<br>'; ?> <?php endforeach; ?> 
2
  • Excellent, many thanks. I have edited my question as I had jcFields instead of jcfields, please can you update your answer for others that may read. Commented Feb 1, 2019 at 16:13
  • Answer updated. Commented Feb 1, 2019 at 21:23

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.