Instantiate any custom field (of type 'text' for instance), set the 'automatic display' to 'no'.
Set a value for this field in an article.
Create a menu item for that single article.
Load the page in the frontend for that menu item.
The custom field value should not show.
The custom field value does not show, yet the layout file /tmpl/the_custom_field.php has been called 4 times.
Joomla 3.7.3 beta, PHP 7.1.0
Preparing the values in getFields() from the helper file is the issue, I think. Fields are 'prepared' before being removed from the list of fields to display.
Therefore, any code that is used to 'prepare' the value in the layout of the field is called multiple times rather than being done only once (or not at all when dynamic display is set to 0).
That means, if you need lo load an external script library for your custom field, for instance, the library will be loaded on the page even though the field does not show.
Labels |
Added:
?
|
Category | ⇒ | com_fields |
Status | New | ⇒ | Information Required |
Can you show me exactly which layout is called 4 times? There are layouts in use to create the HTML value for the field and layouts which are used for automatic display.
I don't understand the distinction you are making.
I am talking about
plugins -> fields -> [field name] -> tmpl -> [field name].php
I came upon this by creating my own plugin.
[field name].php being called several times although the field is automatically displayed to 'not show' (value of 0).
Thank you!
That's why I was asking. This layout is called to create the value
parameter of the field itself. The layout which is called for automatic display is render.php.
I understand that.
What I don't understand is the fact that, when displaying fields on the site (frontend), all fields are selected, 'prepared' then removed if set to 'no show'. Even if they are only meant to be shown on the administrator side only.
When creating a new custom field, are we supposed to create 2 layouts then?
One in plugins -> fields -> [field name] -> tmpl -> [field name].php and one in ?
That is something I did not notice sooner, I just noticed it while creating a new field.
There may be something I am missing here :)
Status | Information Required | ⇒ | Discussion |
Yes
Status | Discussion | ⇒ | Duplicate Report |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-10-01 13:43:14 |
Closed_By | ⇒ | franz-wohlkoenig |
Status | Duplicate Report | ⇒ | Closed |
Closed_Date | 2017-10-01 13:43:14 | ⇒ | 2017-10-01 13:43:15 |
Closed_By | franz-wohlkoenig | ⇒ | joomla-cms-bot |
Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/16775
closed as duplicate Report #17889.
Thanks for Hint @Quy.
onCustomFieldsPrepareDom tests the 'show_on' option. Why not onCustomFieldsPrepareField ? There is no point to prepare a field for the site if it is only meant to be seen in the admin console. That would already take away the multiple 'preparing' of layouts in the frontend that are not needed.