Is there any way to embed Razor code directly into a page (not template)? I basically need one line of code to figure out a URL for a link.
Failing that, is there a way to call a macro without it getting set off as its own paragraph? TinyMCE seems to insist that the macro codeblock can't be contained inside anything else.
I don't think that's possible without editing the Umbraco core.
We'd design a block we could insert on every page with the text as a macro parameter. In this way you can use it in the grid and you can alter the text.
It sounds like you are attempting to embed the data from an umbraco field into the middle of your rich text. In the past, I've seen things like this. It isn't the best user experience in the world, but it gets the job done. It allows a savy user to embed some data into the middle of a rich text editor.
Say that this is the data in your rich text editor. Notice the {{SylabusLink0}} text? You can write some code that searches the rich text editor for that pattern and replaces it with whatever data you like. The trickiest part is trying to add instructions for the user. You don't want them to have to remember what double bracket options are available or how to spell them.
Lorem ipsum dolor sit amet, {{SylabusLink0}} consectetur adipiscing elit. Vivamus euismod libero in libero malesuada, in ornare purus
consectetur. Vestibulum vel dictum dui, non vulputate dolor. Aliquam placerat tincidunt porta. Praesent elementum diam ac
risus imperdiet venenatis. Aliquam erat volutpat. Pellentesque id orci et orci aliquam ultricies vulputate in dolor. Morbi ut
tristique nisl, sit amet euismod mauris. Cras a rutrum eros.
Here is some rough code to replace that double bracket with some data:
var myRichTextData = Model.Content.GetPropertyValue<string>("bodyText");
var myLinkUrl = Model.Content.GetPropertyValue<string>("myLink");
myRichTextData = myRichTextData.Replace("{{SylabusLink0}}", myLinkUrl);
@Html.Raw(myRichTextData)
Thanks for the ideas! I originally had started building a macro to output the hunk of code (basically like Frans was suggesting) but I like Mark's idea. I created a new template and am implementing that.
Embedding Razor directly in a page
Is there any way to embed Razor code directly into a page (not template)? I basically need one line of code to figure out a URL for a link.
Failing that, is there a way to call a macro without it getting set off as its own paragraph? TinyMCE seems to insist that the macro codeblock can't be contained inside anything else.
I don't think I get what you mean... Can you give a code example?
I basically want to do
in the middle of a paragraph on a page.
The page content is going to be copied and reused. I want the link to be calculated dynamically to ensure its correct.
So the paragraph its in will be a RTE, and this link has to be in the middle of the RTE?
Yes.
I don't think that's possible without editing the Umbraco core.
We'd design a block we could insert on every page with the text as a macro parameter. In this way you can use it in the grid and you can alter the text.
Is this a option for you?
It sounds like you are attempting to embed the data from an umbraco field into the middle of your rich text. In the past, I've seen things like this. It isn't the best user experience in the world, but it gets the job done. It allows a savy user to embed some data into the middle of a rich text editor.
Say that this is the data in your rich text editor. Notice the
{{SylabusLink0}}
text? You can write some code that searches the rich text editor for that pattern and replaces it with whatever data you like. The trickiest part is trying to add instructions for the user. You don't want them to have to remember what double bracket options are available or how to spell them.Here is some rough code to replace that double bracket with some data:
Hopefully this helps or gives you some ideas.
That is a possible solution to, but I'm having a hard time to learn our customers how to use a classname let alone a syntax like that.
But hey, there are two solutions now :P
Thanks for the ideas! I originally had started building a macro to output the hunk of code (basically like Frans was suggesting) but I like Mark's idea. I created a new template and am implementing that.
is working on a reply...