Is it possible to access a Razor variable in content?
If one of our editors are writing content and would like to use the our brand name, is there a feature in Umbraco which allows the editor to write a variable in the text?
Example:
Welcome to [brandName]!
..should render the following text to visitors:
Welcome to My Company!
I've been searching for answers with Google and here on the forum without any luck.
for one off replacements great.. but you could extend to use the umbraco dictionary for content replacements?
something like
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
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 { }
Access Razor variable in Content
Hi
Is it possible to access a Razor variable in content?
If you render your content in Razor you could do something like this:
The old Razor macro:
MVC Razor:
Jeroen
for one off replacements great.. but you could extend to use the umbraco dictionary for content replacements?
something like
is working on a reply...