Create a new custom LIST field for articles. (Same pb with Checkbox, did not test all)
For example:
Then edit an article and choose a value. For example "Center"
Then, following the instructions in https://docs.joomla.org/J3.x:Adding_custom_fields/Overrides
edit /components/com_content/views/article/tmpl/default.php
Add after $info = etc.
foreach($this->item->jcfields as $jcfield)
{
$this->item->jcFields[$jcfield->name] = $jcfield;
}
and thereafter
var_dump($this->item->jcFields['article_class']->value);
Where article_class
is the name of my field.
center
Center
In fact, for some of the custom fields, $value = $rawvalue. It is the case for the custom Text field.
But it is not the case for List, Checkboxes, and maybe others I did not check.
For these, the real value is $rawvalue
.
The code to use is therefore
$this->item->jcFields['article_class']->rawvalue
Obviously the docs should be updated to reflect this confusion.
I propose to also add a spacer label displaying when editing these fields.
Any other solution in code would not be B/C
What do you think?
Labels |
Added:
?
|
Status | New | ⇒ | Discussion |
Category | ⇒ | com_fields Documentation |
Labels |
Added:
J3 Issue
|
Modified docs.
Status | Discussion | ⇒ | Known Issue |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-04-30 07:55:09 |
Closed_By | ⇒ | infograf768 | |
Labels |
Labels |
Changed to Known Issue. Does not mean it is right, but, at this stage, it can't be modified for B/C reasons.
Each Article = Multiple Custom Fields and using List Type/Select fields.
We were using
echo $item->jcFields['work-project-types']->value
However since a recent update this is now blank.
My friend Justin found that we needed to go into the back end and enable the Show On (BOTH) option. In order to get the value to display again.
Maybe your find is a new issue. It was reported on a German forum for Joomla 3.9.5 like this:
Before update the ->value
was the Text
of the selected list OPTION
.
Before update the ->rawvalue
was the Value
of the selected list OPTION
.
After update the ->value
is empty.
I've tested it and couldn't confirm the issue but my setting for Show on
was Both
(= Default).
Docs do need to be updated for sure.