This position will not be outputted in the regular custom fields flow, and will only be displayed through a specific code within a template override. The code for individual field placement already exists, kindly provided by @gaelicwinter.
Basic instructions and code were added to the Joomla documentation.
Labels |
Added:
?
|
If i understand you correctly then this can already be done
See https://docs.joomla.org/J3.x:Adding_custom_fields/Overrides
Let me ask this: After I load the fields helper, can I do "echo $item->jcfields->field-alias->field-value" or something like that to target the specific field I need? Or maybe field-id instead of field-alias, if it's decided to not implement field alias.
I'm not a PHP developer, and the code you referred me to is a "foreach", which, as far as I know, will render all fields in the same position.
What I mean, apart from the ability to use a simple one-line code to add just one specific field with the ability to choose between the label or the value, is also to remove the field from the standard flow (i.e. the field will not be rendered in any of the standard positions).
Also:
The fieldshelper could be loaded by default, or maybe using a switch in the template options, to make things easier for everyone.
We could have a field alias, to make targeting fields easier, and have reusable code across sites (especially useful for integrators).
In the top of the override you put this code in order to get a name-based array
foreach($item->jcfields as $jcfield)
{
$item->jcFields[$jcfield->name] = $jcfield;
}
?>
//then down in your layout you reference the field itself
jcFields['field-alias']-value; ?>Sent from my iPhone
On Aug 5, 2017, at 5:34 PM, Jonathan Roza notifications@github.com wrote:
echo $item->jcfields->field-alias->field-value
Sorry I forgot a character:
jcFields['field-alias']->value; ?>Sent from my iPhone
On Aug 5, 2017, at 6:15 PM, gaelicwinter notifications@github.com wrote:
jcFields['field-alias']-value; ?>
That's great!!! Thank's a million @gaelicwinter !
So, "name" is actually "alias". Good to know.
Why not using alias, since most Joomla users are familiar with the term, and "name" might confuse the field with something that would be displayed in the frontend?
Should I load the fields helper with the code
<?php JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php'); ?>
before using your foreach to get the name/alias?
Can I use <?php echo $item->jcFields['field-alias']->label; ?>
to echo the label?
And may I suggest having this named field addressing (plus the FieldsHelper load) implemented at the core by default, so we can just go ahead with the simple one-liner code?
K2 did that and it is a success, with no apparent performance loss.
Also, we still need to create a custom position, to remove the field from the standard flow, so we can use the regular positions + the individually placed fields.
OK I just got home and looked it up. Its actually called 'name', and my
code was not so clear, so the code should read like this.
//Top of template or layout override:
foreach($item->jcfields as $jcfield)
{
$item->jcFields[$jcfield->name] = $jcfield;
}
?>
//In your display layout somewhere:
jcFields['name-of-field']->value; ?> jcFields['name-of-field']->label; ?>//The 'name-of-field' is whatever your field has entered in its 'Name'
field on the field edit form.
=============================================
On Sat, Aug 5, 2017 at 6:42 PM, Jonathan Roza notifications@github.com
wrote:
And may I suggest having this named field addressing (plus the
FieldsHelper load) implemented at the core by default, so we can just go
ahead with the simple one-liner code?
K2 did that and it is a success, with no apparent performance loss.—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#17414 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGNWulBsEiXIEYiqLDENonlVl7ZVrRXeks5sVRoDgaJpZM4OukUD
.
Thanks again @gaelicwinter
Issue updated to include only the request for the custom position.
I've asked Sandra to add the following to the documentation:
https://drive.google.com/open?id=1XitqQrZdFRKu7meNH_sorC_Zu64U7VeFSwFDkToJ0Ww
Category | ⇒ | com_fields Feature Request Layout |
Status | New | ⇒ | Discussion |
Sorry I still dot understand what you mean yesterday custom position
Also the docs site is a wiki so if you think something can be improved then you should try to do it yourself and not ask for someone else to do it
Yesterday = by a
Autocorrect on my phone
@brianteeman
Thank you for the docs hint. I didn't realize it was an open wiki.
As for custom position, I mean this:
I expect that if "no" is selected, fields won't be displayed at all.
Keep in mind I'm used to K2, where if the fields are disabled, individually placed ones won't show.
"No" means they are not displayed automatically. You will have to display it in an override or using the content plugin.
Imho, this issue can be closed.
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-08-06 15:27:05 |
Closed_By | ⇒ | jonrz |
If i understand you correctly then this can already be done
See https://docs.joomla.org/J3.x:Adding_custom_fields/Overrides
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/17414.