Joomla-cms: Custom Fields inserted inside the Article Content

Created on 19 Mar 2017  路  17Comments  路  Source: joomla/joomla-cms

Steps to reproduce the issue

Create new article, withe some text:
In the Content Tab, press de Button "Fields".
Select a custom field and insert it
Yo see this html code:
<p>This is an article text with the {field 1} inserted within this paragraph.</p>

Expected result

You expect to see this html code in the frontend:
<p>This is an article text with the <span class="field-value">field 1 value</span> inserted within this sentence.</p>

Actual result

The actual result is a the inclusion of the description list tag

with the Field Value, so the original paragraph breaks in 3 lines.

    <p>This is an article text with the 
<dd class="field-entry " id="field-entry-1">
        <span class="field-value">field 1 value</span>
</dd>
 inserted in an article.</p>    </div>

System information (as much as possible)

joomla 3.7

Additional comments

No Code Attached Yet

Most helpful comment

@Sukinoz @laoneo I was a bit bored today at work and got an idea: https://github.com/joomla/joomla-cms/pull/15027
This will allow for alternative layouts to be used by the plugin tag. That would allow to customise the appearance of the field within an article body. So you could create a layout which only shows the label or only the value or whatever.

All 17 comments

From my view it麓s actually not really a bug but something that needs indeed huge improvement. The problem is, that you can麓t know how the User wants to implement the specific fields so you can麓t define a specific rendering. What if it麓s not a paragraph but a container? What if the Field is not a value but a slideshow or something?

Maybe it麓s a solution to offer a raw output of the field Value or text without any Label or Markup.
I see that your test, which was very important, shows that this needs some more thoughts.

It needs to be defined how all of the Joomla! Core custom fields would be rendered in Article, Category, Contactinformation and Contactcategory view when automatic display is off.

Maybe better alow to insert the "field title" and "field value" separated.
And insert them inside the article just the field value without tags, because the users know how we wants to implement it, so we will insert them inside a parragraf or a div o watever we need.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/14753.

The plugin uses the JLayout that is used always when a field is rendered. Just override that one and you can adjust it to your needs.
For a single field, it's this layout: https://github.com/joomla/joomla-cms/blob/staging/components/com_fields/layouts/field/render.php

It can be overriden also on component level, eg if you want the fields to render differently in an article, you can do that.

Thanks for replaying

But seems that this layout renders the inclusion Inside de Article (great: you can remove tags from the render.php, and after insert them manualy inside the article text editor if you want), buuuut seems that also this layout renders the "Automatic Display" option (ups, here you need the predefined tags!).

Yep as said, it always uses the same layout, doesn't matter where it is rendered. From a code view there is no difference if it's in the "automatic display" or within an article.

Maybe we need to remove the <dd> from the layout and put add it somewhere else for the automatic display.

Hello @Bakual ,

Thanks for replaying, but what do you mean with this sentence?:

Maybe we need to remove the

from the layout and put add it somewhere else for the automatic display.

Edited my comment above so the tag shows 馃槃

A solution can be to use a second layout for the inline fields or to switch to a template engine (eg. Mustache) like DPFields has and was included in the early stages of com_fields, more information why and why not can be found here https://github.com/joomla-projects/custom-fields/pull/135.

I don't think it needs a second layout. The current one just has to much in it and that <dd> tag should go to the calling layout instead.

Thanks @laoneo and @Bakual for replaying,

From my point of view, the objective of including selected fields inside the article content should be different from the "automatic display", so we need a different way to do it.

Case 1: "AUTOMATIC Display":

  • To display the COMPLETE LIST OF FIELDS (so, with <dd> or <div> it is ok).
  • To display them rendered automatically (with render.php)
  • To display them automatically "After Tittle", "After the article", etc. (as defined in field options).
  • Showing the label or not automatically (as defined in field options).

_...this is how joomla 3.7 is working now. Great. everything automatic, as expected!_

Case 2: "MANUALLY display":
this is the {field x} way, but now J3.7 it is not working as expected (of course, from my point of view)

  • To display ONLY THE SELECTED FIELD manually (only show the fields we manually choose)
  • To display it where we want inside the article content (inserting manually the {field X} )
  • To render it manual (Adding manually the tags we want: <b>{field X}</b>)
  • To select manually if we want to insert the field label or the field value. ({field 1:label} and {field 1:value})

For example:

  • Field 1 label: Year In
  • Field 1 data: 2013
  • Field 2 label: Year Out
  • Field 2 data: 2015

Automatic display:
I expect every fields automatic rendered like this:

<dd class="" id="field-entry-2">
        <span class="field-label">year in: </span>
        <span class="field-value">2013</span>
</dd>
<dd class="" id="field-entry-2">
        <span class="field-label">year out: </span>
        <span class="field-value">2013</span>
</dd>

Manual Display:
I expect i can do something like this:

<p>This article content is about something which 
<b>{field 1:label}</b> was on the <i>{field 1:value}</i>, 
and its <b>{field 2:label}</b> was on the <i>{field 2:value}</i>.</p>

<p>Remember: <span style="font-size: 14pt;">{field 2:value}</span> 
and <span style="font-size: 14pt;">{field 2:value}</span></p>

Of course, it is just my point of view. Thanks for reading.

See https://github.com/joomla/joomla-cms/pull/15013 for fixing the <dd> in the article body.

To select manually if we want to insert the field label or the field value. ({field 1:label} and {field 1:value})

We can improve on that later if someone wants to write the code for it. This should be possible in a B/C manner.
On the other hand you can already set the field label to hide and it will also not show in the article body (so it is possibly to only show the value). If you only want to show the label, you could as well just write it manually.

@bakual thank for replaying,

But reading what you said:

See #15013 for fixing the <dd> in the article body.

And

On the other hand you can already set the field label to hide and it will also not show in the article body (so it is possibly to only show the value)

I see i didnt explain well, because this is not the problen and either the solution.

Maybe my English is not good enough. I am trying to explain again:

Yes i know you can set the field label to hide . I have wrote about it in "_Case 1: Automatic Display_".
It is great to show a "<dd>field label: field value</dd>" list of fields automatically.
<dd> or whatever else (div, table, li...).
This part is working great.

But the problem i am trying to explain here is another:
If after that "automatic display", you want to also insert some fields manually inside the article content (Case 2 Insert manually):

  1. you can not insert only the value.
  2. you can not insert it inside the text of the content. Something like this is imposible:
    <p>This is an article with this <b> {field 1 value} </b> inside the content.<p>

Hope i have explained better now.

Yep, that is true. If you want to have the field both in automatic display shown with the label and in the article without, that is not possible today.
But as said, this should be possible to do later as it has no B/C implications. I will likely not have the time to do it but if anyone else wants to do it should be possible.

I understand.

You dont have time and i dont have enough knowledge to do it. Hope someone has both... ;-)

Thanks for your time!

@Sukinoz @laoneo I was a bit bored today at work and got an idea: https://github.com/joomla/joomla-cms/pull/15027
This will allow for alternative layouts to be used by the plugin tag. That would allow to customise the appearance of the field within an article body. So you could create a layout which only shows the label or only the value or whatever.

Can we close this issue as we have a pr?

closed as we have a Pr #15027

Was this page helpful?
0 / 5 - 0 ratings