?
avatar jonrz
jonrz
5 Aug 2017

Requirements

Create a new field position called: custom (for override).

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.

avatar jonrz jonrz - open - 5 Aug 2017
avatar joomla-cms-bot joomla-cms-bot - change - 5 Aug 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 5 Aug 2017
avatar jonrz jonrz - change - 5 Aug 2017
The description was changed
avatar jonrz jonrz - edited - 5 Aug 2017
avatar brianteeman
brianteeman - comment - 6 Aug 2017

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.

avatar brianteeman
brianteeman - comment - 6 Aug 2017

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.

avatar jonrz
jonrz - comment - 6 Aug 2017

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).

avatar gaelicwinter
gaelicwinter - comment - 6 Aug 2017

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

avatar gaelicwinter
gaelicwinter - comment - 6 Aug 2017

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; ?>
avatar jonrz
jonrz - comment - 6 Aug 2017

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?

avatar jonrz
jonrz - comment - 6 Aug 2017

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.

avatar gaelicwinter
gaelicwinter - comment - 6 Aug 2017

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
.

avatar jonrz jonrz - change - 6 Aug 2017
The description was changed
avatar jonrz jonrz - edited - 6 Aug 2017
avatar jonrz jonrz - change - 6 Aug 2017
The description was changed
avatar jonrz jonrz - edited - 6 Aug 2017
avatar jonrz jonrz - change - 6 Aug 2017
The description was changed
avatar jonrz jonrz - edited - 6 Aug 2017
avatar jonrz jonrz - change - 6 Aug 2017
The description was changed
avatar jonrz jonrz - edited - 6 Aug 2017
avatar jonrz
jonrz - comment - 6 Aug 2017

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

avatar jonrz jonrz - change - 6 Aug 2017
The description was changed
avatar jonrz jonrz - edited - 6 Aug 2017
avatar jonrz jonrz - change - 6 Aug 2017
The description was changed
avatar jonrz jonrz - edited - 6 Aug 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 6 Aug 2017
Category com_fields Feature Request Layout
avatar franz-wohlkoenig franz-wohlkoenig - change - 6 Aug 2017
Status New Discussion
avatar brianteeman
brianteeman - comment - 6 Aug 2017

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

avatar brianteeman
brianteeman - comment - 6 Aug 2017

Yesterday = by a

Autocorrect on my phone

avatar jonrz jonrz - change - 6 Aug 2017
The description was changed
avatar jonrz jonrz - edited - 6 Aug 2017
avatar jonrz
jonrz - comment - 6 Aug 2017

@brianteeman
Thank you for the docs hint. I didn't realize it was an open wiki.

As for custom position, I mean this:
custom_field_position

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.

avatar Bakual
Bakual - comment - 6 Aug 2017

"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.

avatar jonrz
jonrz - comment - 6 Aug 2017

Many thanks @Bakual.
I'll update the docs to reflect that.

avatar jonrz jonrz - change - 6 Aug 2017
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2017-08-06 15:27:05
Closed_By jonrz
avatar jonrz jonrz - close - 6 Aug 2017
avatar laoneo
laoneo - comment - 7 Aug 2017

Just for the record, here is the pr why the field called name and not alias #14554.

Add a Comment

Login with GitHub to post a comment