Copied to clipboard

Flag this post as spam?

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


  • Johan Roug 97 posts 153 karma points
    Dec 19, 2010 @ 00:05
    Johan Roug
    0

    if statement on masterpage

    Hi

    I know nothing of c#, but I need to make an if statement on my masterpage.

    Something like 

    if checkbox with the name "closeComment" is not checked 
              render macro

    Thank you in advance

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Dec 19, 2010 @ 00:10
    Jan Skovgaard
    0

    Hi Johan

    Do you have a specific reason for making this check using c#?

    I'm thinking that it should be possible to make the check using xslt inside the macro for instance?

    /Jan

  • bob baty-barr 1180 posts 1294 karma points MVP
    Dec 19, 2010 @ 00:43
    bob baty-barr
    1

    @johan, if you are able to have a blank instance of umbraco installed locallly you shoudl definitely install the blog4umbraco package as it has the EXACT demonstration of what you are looking for  -- I Believe :)

    they do a check on the master page to see if comments have been marked closed... you should check it out [pardon the pun :)]

  • Johan Roug 97 posts 153 karma points
    Dec 19, 2010 @ 11:10
    Johan Roug
    0

    Jan. Because the macro is a usercontrol not a XSLT.

     

    Bob. Good advice. I'll make a fast test solution and install blog for Umbraco, to retrieve that if statement

  • Johan Roug 97 posts 153 karma points
    Dec 19, 2010 @ 11:31
    Johan Roug
    2

    Worked perfect. Here is the code for anyone interested. On the page I have a checkbox, with the alias "closeComments".

     

    <%@ Master Language="C#" MasterPageFile="~/masterpages/Grid-Nine-Three.master" AutoEventWireup="true" %>
    <script runat="server">
        bool closeComments = false;
    
        void Page_Load(object sender, System.EventArgs ea)
        {
            try
            {
                if (umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("closeComments").Value == "1")
                    closeComments = true;
            }
            catch (System.NullReferenceException) { }
            catch (System.ArgumentException) { }
        }
    </script>
    
    <asp:Content ID="Content" ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
        <div class="grid-nine grid-first">
            <div class="content">
                <umbraco:Macro ID="Macro1" Alias="UCommentListComments" runat="server"></umbraco:Macro>
                <% if (!closeComments)
                   { %>            
                <umbraco:Macro ID="Macro2" RegisterScripts="1" Alias="UCommentForm" runat="server"></umbraco:Macro>
                <% } %>
            </div>
        </div>
    </asp:Content>

Please Sign in or register to post replies

Write your reply to:

Draft