Copied to clipboard

Flag this post as spam?

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


  • Owain Williams 482 posts 1414 karma points MVP 7x c-trib
    Mar 01, 2017 @ 17:12
    Owain Williams
    0

    HTML code within Blog post

    Hi! I'm setting up a new project website where I will share tutorials of what I've learned and one thing I want to do is copy and paste code in to the Grid Layout I have. I thought I could just use the built in <> Code option within the Grid Layout but I've stumbled upon and issue. It shows razor code fine but as soon as I put in any html e.g.

    <ul> tags
    <a href=""> tags
    

    and similar it converts them and make them in to lists, links etc.

    How can I get around this?

    Thanks,

  • Owain Williams 482 posts 1414 karma points MVP 7x c-trib
    Mar 02, 2017 @ 11:34
    Owain Williams
    0

    I've since found what I'm trying to do is prevent the Grid Editor 'Code' from rendering html tags and just show them as text. Still not found the solutions but hopefully that explains what I'm trying to do a bit better?

  • Steve Morgan 1350 posts 4460 karma points c-trib
    Mar 03, 2017 @ 16:21
    Steve Morgan
    0

    Output using @Html.Raw(Model.Content.GetPropertyValue

    Obviously there is inherent danger in not escaping user generated content...

    HTH

  • Sven Geusens 169 posts 881 karma points c-trib
    Mar 03, 2017 @ 16:52
    Sven Geusens
    0

    The easiest thing to do in my opinion is to make a new grid editor in the config/grid.editors.config.js file and add a pre tag to its markup

    add the following entry

    {
        "name": "Code",
        "alias": "code",
        "view": "textstring",
        "icon": "icon-coin",
        "config": {
            "style": "border: 3px dashed black; background-color:grey",
            "markup": "<pre class="codeblock">#value#</pre>"
        }
    }
    

    You should now have a Code option when adding new content to a row in the grid.

    The style part is how it gets rendered in the grid in the backoffice.

    To style it on the page use the included codeblock class.

    More information can be found on: https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/grid-layout/build-your-own-editor

  • Owain Williams 482 posts 1414 karma points MVP 7x c-trib
    Mar 03, 2017 @ 17:24
    Owain Williams
    0

    Hi, I tried this and it works in the backoffice but on the frontend it still renders everything as HTML e.g. if I put a something I will just get the word something displayed as a link. The pre tags are around it but it doesn't seem to make any difference.

    O.

  • Sven Geusens 169 posts 881 karma points c-trib
    Mar 04, 2017 @ 15:57
    Sven Geusens
    0

    When I render the grid like this:

    @Html.GetGridHtml(Model.Content, "grid")

    I get the following

    enter image description here

  • Owain Williams 482 posts 1414 karma points MVP 7x c-trib
    Mar 06, 2017 @ 11:30
    Owain Williams
    0

    Hi After some testing over the weekend it seems that if I use the <> CODE button to choose type of content, it renders the HTML code as a link or a paragraph etc. which is what I didn't want. If I however type the code in to the RTE option and style it with my 'code' css, it works perfectly. At least I have an option now for typing code in to my blogs. Not sure why one works and the other doesn't. I'll look into that at a later date.

    Thanks for your help everyone!

    enter image description here

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies