Copied to clipboard

Flag this post as spam?

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


  • Jon 8 posts 89 karma points
    Dec 03, 2024 @ 22:58
    Jon
    0

    Using razor script to display an html field

    I am using Umbraco 7

    I have a page with a series of podcast episodes. I have transcripts for those episodes. I have made a link to retrieve and display the transcript while listening to it. I have made the link so it posts back to the same page and retrieves the transcript.

    I can't get the transcript to display.

    @{
    var transId = 0;
    var theTranscript = "";
    if(!string.IsNullOrEmpty(Request.QueryString["transcript"])) {
        Int32.TryParse(HttpContext.Current.Request.QueryString["transcript"].ToString(), out transId);  
    
        theTranscript = Umbraco.Content(transId).transcript;
        <script type="text/javascript">
            window.onload = function () {
                $('#transcript').html(theTranscript);
            };
        </script>
    }
    

    }

    The transcript is entered using a rich text editor. I've looked in the database and the text is there. If I set the transcript field using a plain string, it displays fine.

    I'd appreciate any help.

    Jon

  • Robert Sikkens 7 posts 78 karma points
    Dec 05, 2024 @ 16:12
    Robert Sikkens
    0

    Think your javascript is not working, try

     window.onload = function () {
            $('#transcript').html('@theTranscript');
        };
    
  • Jon Behrens 13 posts 153 karma points
    Dec 05, 2024 @ 17:35
    Jon Behrens
    0

    Thanks for your answer. Sadly, I've tried that and it doesn't work either.

    If I replace the variable 'theTranscript' (either with or without the '@') with a static string, it works fine. For some reason, 'theTranscript' is not being set.

  • Robert Sikkens 7 posts 78 karma points
    Dec 06, 2024 @ 09:50
    Robert Sikkens
    0

    Should work if you got your name right Umbraco.Content(transId) returns DynamicPublishedContent. transId is the id from the node your want, check if Alias from the documenttype 'transcript', and get page like this url/view?transcript=1234

  • Jon Behrens 13 posts 153 karma points
    Dec 06, 2024 @ 16:58
    Jon Behrens
    100

    Thanks again for the help. I finally said 'to heck with it' and wrote a macro. Works fine now.

    @{  
    var transId = 0;
    var theTrans = ""; 
    if(!string.IsNullOrEmpty(Request.QueryString["transcript"])) {
        Int32.TryParse(HttpContext.Current.Request.QueryString["transcript"].ToString(), out @transId); 
        theTrans = Umbraco.Media(@transId).transcript;
        <div id='transcript'>
            <p>Transcript for <span>@Umbraco.Media(@transId).Name</span></p>
            @Html.Raw(@theTrans)
        </div>
    }
    

    }

  • Alex Skrypnyk 6176 posts 24187 karma points MVP 8x admin c-trib
    Dec 06, 2024 @ 17:09
    Alex Skrypnyk
    0

    Thanks for sharing this with community!

Please Sign in or register to post replies

Write your reply to:

Draft