Closed khalwat closed 6 years ago
You need to preserve the reference somehow.
In case of element URLs the reftag is preserved using a hash
http://example.com/news/my-entry#entry:79
For plain text one option would be to preserve it using data attribute on a span tag.
<span data-reftag="globalset:737:loanName">My Loan Name</span>
I think it would be nice if Craft would allow Plugins to hook into RichTextFieldType’s onGetInputHtml()
and prepValue()
to parse and preserve reference tags or other types of shortcodes and prepare them for output.
@MakeilaLundy @Radabaugh let's see if we can get this fixed for Craft 2.
@brandonkelly Any update on this? This is somewhat critical for a project we work on...
If you insert a Reference Tag (https://craftcms.com/docs/reference-tags) such as
{globalset:737:loanName}
into a Rich Text field, an attempt is made to preserve them: https://github.com/craftcms/cms/blob/develop/src/fields/RichText.php#L246And then they are parsed via
Elements->parseRefs
-- the problem is that the preservation only appears to work for the Asset and Entry links that Craft is specifically looking for.When
serializeValue()
is called to save the RTF data, it attempts to convert them back into reftags: https://github.com/craftcms/cms/blob/develop/src/fields/RichText.php#L326But this fails to work for any reference tags that are not Asset or Entry links, such as the above example.
What happens is that the reftag is saved properly the first time (and is properly parsed as output as per https://github.com/nystudio107/craft3-richvariables ) but editing that Entry again will cause the parsed text to be in the RTF, not the reftag. So if the entry is saved a second time, the tagref disappears, and reftag is no longer parsed.
Expected result:
(This is present in both Craft 2.x and Craft 3.x)