Copied to clipboard

Flag this post as spam?

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


  • Lex Godthelp 15 posts 99 karma points
    Mar 21, 2017 @ 15:09
    Lex Godthelp
    0

    Checking if a MACRO gives output

    Hello guys,

    I was wondering if there was any way to check if a certain macro gives an output like so:

    @if(Model.Content.HasValue("expertBijBlog")){
        <div class="hidden-xs hidden-sm hidden-md col-lg-3"><h3>Expert:</h3></div>
    }else if(MACRO HAS VALUE){
        <div class="hidden-xs hidden-sm hidden-md col-lg-3"><h3>Gerelateerd:</h3></div>
    }
    

    Could anyone help me out?

    Thanks,

    ~Lex

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 05, 2017 @ 19:00
    Alex Skrypnyk
    0

    Hi Lex

    You can use RenderMacro method and then check if there some data after rendering, but it's not a good idea. Like that:

    var macroOutput = Umbraco.RenderMacro("myMacroAlias");
    
    @if(Model.Content.HasValue("expertBijBlog")){
        <div class="hidden-xs hidden-sm hidden-md col-lg-3"><h3>Expert:</h3></div>
    }else if(!string.IsNullOrEmpty(macroOutput)){
        <div class="hidden-xs hidden-sm hidden-md col-lg-3"><h3>Gerelateerd:</h3></div>
    }
    

    Thanks,

    Alex

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 20, 2017 @ 12:10
    Alex Skrypnyk
    0

    Hi Lex

    Did you find out how to do it?

    Do you have something to share with community?

    Thanks,

    Alex

  • Lex Godthelp 15 posts 99 karma points
    Apr 20, 2017 @ 12:34
    Lex Godthelp
    100

    Hi Alex,

    I was quite busy and completely forgot about this post. I just looked at your solution and it works, except for a minor detail i added:

                @{
                    var macroOutput = Umbraco.RenderMacro("Macro");
    
                    if(Model.Content.HasValue("Valuefield")){
                        <div class="hidden-xs hidden-sm hidden-md col-lg-3"><h3>Do this:</h3></div>
                    }else if(!string.IsNullOrEmpty(macroOutput.ToString())){
                        <div class="hidden-xs hidden-sm hidden-md col-lg-3"><h3>Do That:</h3></div>
                    }
                }
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 20, 2017 @ 12:36
    Alex Skrypnyk
    0

    Glad that you solved it, thanks for sharing!

    Have a nice day.

    /Alex

Please Sign in or register to post replies

Write your reply to:

Draft