None, it just happens
See Below
See Below
J5.0.1
Chrome Browser
When I add a text type custom field in an article an extra space is added directly after the content of the field. I've double checked my entries for additional spaces, there are none.
Article text in editor
operates in {field 6}, {field 7}. We cover........
Rendered article text in browser
operates in Basingstoke , Hampshire . We cover.....
You can see the extra space being rendered before the , and the .
Code from Console
<p>operates in <span class="field-value ">Basingstoke</span>
, <span class="field-value ">Hampshire</span>
. We cover......</p>
This is exactly how the code is produced in the page, a bit "janky" I'd say, but may have no bearing on the issue.
This issue only seems to happen if the field is immediately followed by punctuation, if it's followed by another word there's no extra space. Although in other places in the article the field is followed by a dash ( - ) with no extra space. But, if followed by a ( ? ) then an extra space is inserted between the field and the ( ? )
Merry Christmas everyone.
Labels |
Added:
No Code Attached Yet
|
confirmed
Labels |
Added:
bug
|
Here's a potential solution using the FieldsHelper::render()
function that might help resolve this problem:
Override the Render Method: You can override the FieldsHelper::render()
method in your template or plugin to control how the fields are outputted.
// Load the FieldsHelper
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
// Get the custom fields for a specific item
$jcFields = FieldsHelper::getFields('com_content.article', $item, true);
// Loop through the fields and render them without extra spaces
foreach($jcFields as $field) {
// Render the field and trim any whitespace
$fieldOutput = trim(FieldsHelper::render($field->context, 'field.render', array('field' => $field)));
echo $fieldOutput;
}
In this snippet, trim()
is used to remove any leading or trailing whitespace from the rendered field output.
Hope this helps!
chatGPT is not a solution
chatGPT is not a solution
Actually I tried solving using the same logic and code only, but for explanation I used ChatGPT
... and did you actually try the code? Did it really solve the reported problem?
... and did you actually try the code? Did it really solve the reported problem?
Yeah, the code mentioned above isn't the actual code, there's a different code but for like validation if my approach is correct I provided the sample code. I will be raising a PR with the actual code which is solving this problem
Just wondering if anyone on the team has seen this yet?