Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Sep 26, 2014 @ 19:22
    Steve
    0

    Syntax Issue

    Could someone tell me why this is not saving?

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
        var page = Model.AncestorOrSelf("Category2HomePage");
    
        if ( page.contactPhone != "" && page.contactEmail != "" && page.contactPhone2 != "" && page.contactEmail2 != "") {
            <a class="hide_email" rel="@page.contactEmail">@page.contactPhone</a>
                <br />
                <a class=" hide_email" rel="@page.contactEmail2">@page.contactPhone2</a>
                } else
        {
            if (page.contactPhone != "" && page.contactEmail != "" && page.contactPhone2 != "") {
            <a class="hide_email" rel="@page.contactEmail">@page.contactPhone</a>
                <br />
                @page.contactPhone2
                }
        } else 
    
        { 
         if (page.contactEmail != "" && page.contactEmail2 != "") {
             <a class=" show hide_email" rel="@page.contactEmail">@page.contactEmail</a>
                 <br />
             <a class=" show hide_email" rel="@page.contactEmail2">@page.contactEmail2</a>
                 }
        } else
         {
         if (page.contactPhone != "" ) {
            @page.contactPhone
                <br />
        }
         if (page.contactEmail != "") {
            <a class=" show hide_email" rel="@page.contactEmail">@page.contactEmail</a> 
        }
         if (page.contactPhone2 != "" ) {
             @page.contactPhone2
                 <br />
        }
         if (page.contactEmail2 != ""){
            <a class=" show hide_email" rel="@page.contactEmail2">@page.contactEmail2</a>
            }
    
        }
    }
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 26, 2014 @ 19:44
    Dennis Aaen
    0

    Hi Steve,

    What if you do something like this:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
        var page = Model.AncestorOrSelf("Category2HomePage");

        if (page.contactPhone != "" && page.contactEmail != "" && page.contactPhone2 != "" && page.contactEmail2 != "") {
                <a class="hide_email" rel="@page.contactEmail">@page.contactPhone</a>
                <br />
                <a class=" hide_email" rel="@page.contactEmail2">@page.contactPhone2</a>
        } else{
            if (page.contactPhone != "" && page.contactEmail != "" && page.contactPhone2 != "") {
                <a class="hide_email" rel="@page.contactEmail">@page.contactPhone</a>
                <br     />
                @page.contactPhone2
            }else{
                if (page.contactEmail != "" && page.contactEmail2 != "") {
                     <a class=" show hide_email" rel="@page.contactEmail">@page.contactEmail</a>
                         <br />
                     <a class=" show hide_email" rel="@page.contactEmail2">@page.contactEmail2</a>
                }else{
                    if (page.contactPhone != "" ) {
                        @page.contactPhone
                        <br />
                    }
                    if (page.contactEmail != "") {
                        <a class=" show hide_email" rel="@page.contactEmail">@page.contactEmail</a>
                    }
                }
                if (page.contactPhone2 != "" ) {
                    @page.contactPhone2
                    <br />
                }
                if (page.contactEmail2 != ""){
                    <a class=" show hide_email" rel="@page.contactEmail2">@page.contactEmail2</a>
                }
            }
       
        }
    }

    Hope this helps,

    /Dennis

  • Steve 472 posts 1216 karma points
    Sep 26, 2014 @ 19:57
    Steve
    0

    Thanks, but I am still receiving an error around the middle else statement.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 26, 2014 @ 20:00
    Dennis Aaen
    0

    Hi Steve,

    Did you get the error when you try saving the file or on the frontend of your website?

    /Dennis

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 26, 2014 @ 20:40
    Dennis Aaen
    0

    Hi Steve,

    What if you are trying this:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
        var page = Model.AncestorOrSelf("Category2HomePage");

        if (page.contactPhone != "" && page.contactEmail != "" && page.contactPhone2 != "" && page.contactEmail2 != "") {
            <a class="hide_email" rel="@page.contactEmail">@page.contactPhone</a>
                <br />
            <a class=" hide_email" rel="@page.contactEmail2">@page.contactPhone2</a>
        }
        if (page.contactPhone != "" && page.contactEmail != "" && page.contactPhone2 != "") {
            <a class="hide_email" rel="@page.contactEmail">@page.contactPhone</a>
            <br     />
            @page.contactPhone2
        }
        if (page.contactEmail != "" && page.contactEmail2 != "") {
             <a class=" show hide_email" rel="@page.contactEmail">@page.contactEmail</a>
                 <br />
             <a class=" show hide_email" rel="@page.contactEmail2">@page.contactEmail2</a>
        }
        if (page.contactPhone != "" ) {
            @page.contactPhone
            <br />
        }
        if (page.contactEmail != "") {
            <a class=" show hide_email" rel="@page.contactEmail">@page.contactEmail</a>
        }
        if (page.contactPhone2 != "" ) {
            @page.contactPhone2
            <br />
        }
        if (page.contactEmail2 != ""){
            <a class=" show hide_email" rel="@page.contactEmail2">@page.contactEmail2</a>
        }
       
    }

    As I understand your code you are checking that the one of these page.contactPhone != "" && page.contactEmail != "" && page.contactPhone2 != "" && page.contactEmail2 != "" fields not are empty, if so you are going to the next if statement if (page.contactPhone != "" && page.contactEmail != "" && page.contactPhone2 != "") and so on.

    Hope this helps,

    /Dennis

  • Steve 472 posts 1216 karma points
    Sep 26, 2014 @ 22:09
    Steve
    0

    I've got some of it to work, but for some reason my else isn't working.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
        var page = Model.AncestorOrSelf("Category2HomePage");
    
        if ( page.contactPhone != "" && page.contactEmail != "" ) {
            <a class="hide_email" rel="@page.contactEmail">@page.contactPhone</a>
                }
        if (page.contactPhone2 != "" && page.contactEmail2 != "") {
            <a class=" hide_email" rel="@page.contactEmail2">@page.contactPhone2</a>
                }
        else {
                if (page.contactPhone != "" ) {
                    @page.contactPhone
    
                }
                if (page.contactEmail != "") {
    
                    <a class="show hide_email" rel="@page.contactEmail">@page.contactEmail</a>
                    <br />
                }
                 if (page.contactPhone2 != "") {
                     <br />
                    @page.contactPhone2
    
                }
                 if (page.contactEmail2 != "" ) {
                <a class="show hide_email" rel="@page.contactEmail2">@page.contactEmail2</a>
                }
    
        }
        }
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 26, 2014 @ 23:35
    Dennis Aaen
    0

    Hi Steve,

    I think I found a solution to you. I will explain it step by step, and hope it meet your needs

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
        var page = Model.AncestorOrSelf("Category2HomePage");

       
        if (page.contactPhone != "" && page.contactEmail != "" && page.contactPhone2 == "" && page.contactEmail2 == "") {

            <a class="hide_email" rel="@page.contactEmail">@page.contactPhone</a>
               
        }
        if (page.contactPhone2 != "" && page.contactEmail2 != "" && page.contactPhone == "" && page.contactEmail == "") {
            <a class=" hide_email" rel="@page.contactEmail2">@page.contactPhone2</a>
                }
        else {
                if (page.contactPhone != "" ) {
                    @page.contactPhone
                    <br />

                }
                if (page.contactEmail != "") {

                    <a class="show hide_email" rel="@page.contactEmail">@page.contactEmail</a>
                    <br />
                }
                 if (page.contactPhone2 != "") {
                 
                    @page.contactPhone2
                    <br />   

                }
                 if (page.contactEmail2 != "" ) {
                    <a class="show hide_email" rel="@page.contactEmail2">@page.contactEmail2</a>
                }

        }
    }

    The way his code is working is if the fields contactPhone and contactEmail not are empty but both contactPhon2 and contactEmail2 then you will get this out,

     <a class="hide_email" rel="@page.contactEmail">@page.contactPhone</a>

    If the fields contactPhone and page.contactEmail are empty but both contactPhon2  and contactEmail2 fill out then you will get this out,

    <a class=" hide_email" rel="@page.contactEmail2">@page.contactPhone2</a>

    If the one of the contactPhone2  and contactEmail2 are empty and you have fill out all the fields then you will get them out. lets say that the contactEmail2 are empty then you will get contactPhone and contactEmail and  contactPhone2

    Maybe you need to adjust the use of break tags to meet your requirements else could you please try explain what data you are expecting in the different scenarios

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft