Copied to clipboard

Flag this post as spam?

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


  • gilad 185 posts 425 karma points
    Nov 28, 2011 @ 17:33
    gilad
    0

    different render for macros in editor

    hii umbraco team.

    in macro properties there is two checkbox:

    Use in editor , Render content in editor

    i think it will be grate to put another checkBox for :

    diffrent render for editor

    and multiLine textbox for HTML or even a simple image field.

    a lot of macro can't render properly in editor ( scripts , css and so.. )

    and even a diffrent image for editor render will be great..

    thanks in advance.

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 28, 2011 @ 17:50
    Tom Fulton
    0

    Hi,

    Check out this wiki article, in your macro you can detect if it's being displayed in the editor and show different content if desired:  http://our.umbraco.org/wiki/how-tos/add-dummy-text-to-your-macros-in-the-richtext-editor

    Hope this helps,
    Tom

  • gilad 185 posts 425 karma points
    Nov 28, 2011 @ 18:01
    gilad
    0

    hii tom,

    thanks for the quick replay..

    that could be help.. but my macro is rendring cshtml(razor) , not xslt...

    there is a translate for this if?

    thanks again.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 28, 2011 @ 18:29
    Tom Fulton
    0

    Hi,

    It should be translateable to Razor also - it's just checking to see what page it's being called from (if the URL contains macroResultWrapper) using the HTTP_URL ServerVariable.  Unfortunately I know nothing about Razor yet so can't help you with the syntax.  Sorry!

    -Tom

  • gilad 185 posts 425 karma points
    Nov 28, 2011 @ 19:00
    gilad
    0

    hii tom and thanks again.

    till now i can't get it work..

    i try to translate for razor like that :

    if (umbraco.library.RequestServerVariables("HTTP_URL").Contains("macroResultWrapper"))

    {}

    it is not working..

    i try also just to display the : umbraco.library.RequestServerVariables("HTTP_URL")

    but i see nothing..

    thanks for trying..

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 28, 2011 @ 19:23
    Tom Fulton
    0

    Hi,

    This seems to work for me, hopefully for you as well:

      @if (umbraco.library.RequestServerVariables("HTTP_URL").Contains("macroResultWrapper")) {
        <p>rendering from editor</p>
      }
      else {
        <p>not rendering from editor</p>
      }

    -Tom

  • gilad 185 posts 425 karma points
    Nov 28, 2011 @ 19:29
    gilad
    0

    hii.. that exactlly what i am try to do...

    not work for me...

    i add this to the macro script  -  macroScript/macroName.cshtml

  • gilad 185 posts 425 karma points
    Nov 28, 2011 @ 19:41
    gilad
    1

    SLOVED..

    change to : (HTTP_URL  --> URL)

    if (umbraco.library.RequestServerVariables("URL").Contains("macroResultWrapper"))

    {

       is render from editor

    }

  • Jon Dunfee 199 posts 468 karma points
    Apr 06, 2014 @ 06:51
    Jon Dunfee
    0

    Now it's time to figure this out for Umbraco 7.

  • Jonas Eriksson 930 posts 1825 karma points
    Apr 06, 2014 @ 07:30
    Jonas Eriksson
    3

    Sample url now: 

    /umbraco/backoffice/UmbracoApi/Macro/GetMacroResultAsHtmlForEditor?macroAlias=MyMacro

    So (or use the umbraco library function):

    @if(Request.RawUrl.Contains("GetMacroResultAsHtmlForEditor")){
    <span>you are in the editor</span>
    }

     

  • Jon Dunfee 199 posts 468 karma points
    Apr 06, 2014 @ 07:41
    Jon Dunfee
    0

    Sure enough. That did the trick. Thanks!

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Sep 28, 2018 @ 13:19
    Dan Diplo
    0

    For more modern Umbraco sites then you can check:

    UmbracoContext.IsFrontEndUmbracoRequest
    

    If true then it's the front-end of the site; if false then it's in the editor. You can then use this to render conditional content e.g.

    @if (UmbracoContext.IsFrontEndUmbracoRequest)
    {
        <div>
            Your macro for front-end
        </div>
    }
    else
    {
        <div>
            The stuff you want to show in the rich-text editor macro holder
        </div>
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft