there is another way... rather than individual macros in the RTE you can replace your <umbraco:Item field="contents" runat="server" /> (or whatever your rte content param is) with a macro that replaces tokens in that content.
You need to remember to grab the rte content and render any macros already in it using the umbraco.library.RenderMacroContent(String, NodeId); if you do already use macros in the content.
we went with {#XXXX} to keep consistent with the shorthand for dictionary items elsewhere.
something like the below in a usercontrol macro worked for us.
#region replace any dictionary items
try
{
Regex regDictionaryItem = new Regex(@"{#([^}]*)}", RegexOptions.IgnoreCase);
MatchCollection ms = regDictionaryItem.Matches(umbraco.library.StripHtml(doc.InnerXml));
foreach (Match match in ms)
{
try
{
// make replacements in the content xml text nodes only, for any matching definition term
// get all text nodes (reset as the previous lookup may have generated more textnodes)
// filter to what we are looking for allow for upper and lower as xpath is case-sensitive
// NB this might have false matches as not looking for words, but does filter in the right direction
doc.DocumentElement.SetAttribute("searchAttribute0", match.Groups[0].Value);
XmlNodeList textNodes = doc.SelectNodes("//text() [contains(.,//@searchAttribute0)]");
for (var i = 0; i < textNodes.Count; i++)
{
//loop throught the matched textnodes to replace on a word matching basis
textNodes[i].InnerText = textNodes[i].InnerText.Replace(match.Groups[0].Value, umbraco.library.GetDictionaryItem(match.Groups[1].Value));
}
}
catch
{
UmbracoJPT.Utils.Files.WriteToLogFile("error", @"DICTIONARYITEM ERROR" + match.Groups[0].Value + @" ", true);
}
}
}
catch { }
#endregion
Is it possible to use Dictionary item from within RTE?
Hi guys.
If so, please, suggest corresponding syntax.
PS.
That's for translation purposes.
Hi Ivan
In short the answer is no.
The only way you can add text that uses dictionary items into RTE is by using a macro.
Could you perhaps try to describe your scenario and why you would need to be able to use dictionary items within the RTE field?
Looking forward to hearing from you.
/Jan
Thanks for the answer, Jan.
I was inteded to translate text on the sidebar blocks.
there is another way... rather than individual macros in the RTE you can replace your <umbraco:Item field="contents" runat="server" /> (or whatever your rte content param is) with a macro that replaces tokens in that content.
You need to remember to grab the rte content and render any macros already in it using the umbraco.library.RenderMacroContent(String, NodeId); if you do already use macros in the content.
we went with {#XXXX} to keep consistent with the shorthand for dictionary items elsewhere.
something like the below in a usercontrol macro worked for us.
is working on a reply...