Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brian Powell 44 posts 199 karma points c-trib
    Dec 14, 2015 @ 15:35
    Brian Powell
    0

    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.

  • Frans de Jong 548 posts 1840 karma points MVP 3x c-trib
    Dec 14, 2015 @ 15:50
    Frans de Jong
    0

    I don't think I get what you mean... Can you give a code example?

  • Brian Powell 44 posts 199 karma points c-trib
    Dec 14, 2015 @ 15:53
    Brian Powell
    0

    I basically want to do

    View the syllabus <a href="@CurrentPage.Parent.SyllabusPage[0].Url">here</a>.
    

    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.

  • Frans de Jong 548 posts 1840 karma points MVP 3x c-trib
    Dec 14, 2015 @ 15:57
    Frans de Jong
    0

    So the paragraph its in will be a RTE, and this link has to be in the middle of the RTE?

  • Brian Powell 44 posts 199 karma points c-trib
    Dec 14, 2015 @ 15:58
    Brian Powell
    0

    Yes.

  • Frans de Jong 548 posts 1840 karma points MVP 3x c-trib
    Dec 14, 2015 @ 16:26
    Frans de Jong
    0

    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?

  • Mark Bowser 273 posts 860 karma points c-trib
    Dec 14, 2015 @ 16:26
    Mark Bowser
    0

    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)
    

    Hopefully this helps or gives you some ideas.

  • Frans de Jong 548 posts 1840 karma points MVP 3x c-trib
    Dec 14, 2015 @ 16:29
    Frans de Jong
    0

    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

  • Brian Powell 44 posts 199 karma points c-trib
    Dec 14, 2015 @ 16:44
    Brian Powell
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft