Hi, we have some values that we don't want to be hard-coded in Umbraco. What would be the best approach to let user insert pre-definied "variables" in editor and then render those variables ?
For exemple i would like to let my users create content such as :
"You have until $$LIMIT_DATE$$ to send us bla bla bla..."
And then have some code to replace variables ($$xyz$$) with values coming from a DB.
In that helper you can look for your special characters and replace it with a value. The only problem with this solution is that you need to access the database every pageload.
To prevent that I would store the values in a settingsnode. Than it is cached and available as a Model so you can do something like:
A very basic implementation would be something like:
var richText = Model.Content.GetPropertyValue<IHtmlString>("content"); // or from model if you use model builder
var replaced = new HtmlString(richText.ToString().Replace("$$LIMIT_DATE$$", replacementValue));
Then it will run the default ConvertIntermediateToObject method on your replaced content, making sure that links and macros work as expected.
Remember to remove the original RteMacroRenderingValueConverter, so your own implementation gets used. It's described here: Registering PropertyValueConverters
Hi Everyone, Can you please help me how to fetch stored textstring value/textbox value into rich text editor?
Here in the below image, I created 3 folders using document type, each folder contains 15 websites. I have created multiple websites and each website contains separate domains. Specialist Name is in textstring/textbox format example "xyz" i tried fetching that stored value in below rich text editor by using @Model.Value("specialityName") but in website its not displaying the value of textstring. Please suggest me any link or your ideas.
Let user insert variables in rich content editors
Hi, we have some values that we don't want to be hard-coded in Umbraco. What would be the best approach to let user insert pre-definied "variables" in editor and then render those variables ?
For exemple i would like to let my users create content such as : "You have until $$LIMIT_DATE$$ to send us bla bla bla..."
And then have some code to replace variables ($$xyz$$) with values coming from a DB.
Thank you
Interesting case.
I think I would use a helper in the view. Something like:
In that helper you can look for your special characters and replace it with a value. The only problem with this solution is that you need to access the database every pageload. To prevent that I would store the values in a settingsnode. Than it is cached and available as a Model so you can do something like:
Frans
A very basic implementation would be something like:
Thanks Frans and Dan, two great ideas.
I was looking for something more generic : a solution that would apply to all views maybe.
Can you elaborate more on what you are trying to do? The solutions above are usable in every view.
Hi Alexandre
You could implement your own value converter for the rich text editor.
The easiest way would be to inherit from RteMacroRenderingValueConverter, and just override ConvertIntermediateToObject with your logic.
I guess it would look something like
Then it will run the default ConvertIntermediateToObject method on your replaced content, making sure that links and macros work as expected.
Remember to remove the original RteMacroRenderingValueConverter, so your own implementation gets used. It's described here: Registering PropertyValueConverters
Hi Everyone, Can you please help me how to fetch stored textstring value/textbox value into rich text editor?
Here in the below image, I created 3 folders using document type, each folder contains 15 websites. I have created multiple websites and each website contains separate domains. Specialist Name is in textstring/textbox format example "xyz" i tried fetching that stored value in below rich text editor by using @Model.Value("specialityName") but in website its not displaying the value of textstring. Please suggest me any link or your ideas.
Heya,
Looks like easiest way would be helper. In addition, you might use macros if you can narrow down use-cases for your variables.
is working on a reply...