Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 370 posts 1021 karma points
    Mar 17, 2014 @ 12:47
    Paul Griffiths
    0

    If statement within template

    Hi all,

    Im trying to write an if statement with an umbraco template and based on the test i want to render different things.

    Im trying to test whether the current logged in member is an owner of a venue (alias = venueOwner) and if they are show edit venue user control but if they are not just show venue info.

    I keep getting syntax errors can someone advise me on the best way to test whether the current logged in member matches a property?

    eg

    <% if (Membership.GetUser() != null ) { %>
    
        <!--if member is logged in and is the venue owner, show the update venue form-->
    
    <%} %>
    
       <%else {%>       
        <!--else show the full venue display here for end users and people who dont own the venue-->
       <%} %> 
    

    The syntax above works if a member is logged in but if a logged in member views a venue they don't own then still no venue info is displayed.

    i need a test that says if a member is the venue owner then show them the edit form otherwise for non members and members who dont own the venue just show the venue info. However im unsure of the sytax and keep getting errors :(

    Ive tried <% if (Membership.GetUser() != (umbraco.library.GetItem("venueOwner"))) { %>

    Any help would be a bonus :)

    Cheers

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 17, 2014 @ 12:54
    Jeroen Breuer
    0

    Hello,

    It might be easier to convert this code to a Razor macro because it's more flexible.

    Jeroen

  • Paul Griffiths 370 posts 1021 karma points
    Mar 17, 2014 @ 13:02
    Paul Griffiths
    0

    Hi Jeroen

    Thanks for the reply mate. TBH ive not done much with Razor as of yet so just looking for a quick fix this way for the time being (if I can).

    Ive also tried this but still getting syntax error im obviously missing something here lol

    <% if (Membership.GetUser() != (umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("venueOwner")) ) { %>
    

    CS0019: Operator '!=' cannot be applied to operands of type 'System.Web.Security.MembershipUser' and 'umbraco.presentation.nodeFactory.Property'

    Cheers

    Paul

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 17, 2014 @ 13:06
    Jeroen Breuer
    0

    If you want a quick fix this might work:

    <% if (Membership.GetUser() != (umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("venueOwner").Value) ) { %>

    Jeroen

  • Paul Griffiths 370 posts 1021 karma points
    Mar 17, 2014 @ 13:11
    Paul Griffiths
    0

    Thanks again for your reply but still no luck I have the following error :(

    CS0019: Operator '!=' cannot be applied to operands of type 'System.Web.Security.MembershipUser' and 'string'

    Thanks

    Paul

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 17, 2014 @ 13:15
    Jeroen Breuer
    1

    I think this might be it:

    <% if (Membership.GetUser().UserName != (umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("venueOwner").Value) ) { %>

    Jeroen

  • Paul Griffiths 370 posts 1021 karma points
    Mar 17, 2014 @ 13:31
    Paul Griffiths
    0

    Yeah that worked jeroen but i need the id of the member becuase the value being stored in the venue owner alias is an integer.

    We are nearly there tho ha

    Paul

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 17, 2014 @ 13:35
    Jeroen Breuer
    100

    You could try the following than ;-)

    <% if (Membership.GetUser().ProviderUserKey.ToString() != (umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("venueOwner").Value) ) { %>

    Or

    <% if (umbraco.cms.businesslogic.member.Member.GetCurrentMember().Id.ToString() != (umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("venueOwner").Value) ) { %>

    Jeroen

  • Paul Griffiths 370 posts 1021 karma points
    Mar 17, 2014 @ 13:53
    Paul Griffiths
    0

    Hi Jeroen,

    Those statements worked for ok for when a user is logged in but it errors when a user is not logged in because it is looking for the current member so i need to test if member.getUser is null as well.

    is it something like this but this gives me syntax error?

    <% if ((Membership.GetUser() != null) && (umbraco.cms.businesslogic.member.Member.GetCurrentMember().Id.ToString() != (umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("venueOwner").Value) )) { %>

    Paul

  • Paul Griffiths 370 posts 1021 karma points
    Mar 17, 2014 @ 13:57
    Paul Griffiths
    0

    This did the trick jeroen

    Thanks for you help and time mate! Very much apreciated!

    <% if (Membership.GetUser() != null && umbraco.cms.businesslogic.member.Member.GetCurrentMember().Id.ToString() == (umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("venueOwner").Value) ) { %>
    

    Paul :)

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 17, 2014 @ 13:59
    Jeroen Breuer
    1

    Ok I thought a member was always logged on. This check should do the trick:

    <% if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated && (Membership.GetUser().ProviderUserKey.ToString() == umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("venueOwner").Value)) { %>

    This code first checks if the member is logged on and after that if the member id is the same as the id stored in the venueOwner property.

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 17, 2014 @ 14:00
    Jeroen Breuer
    1

    Looks like you already found out yourself. Glad I could help :-).

    Jeroen

  • Paul Griffiths 370 posts 1021 karma points
    Mar 17, 2014 @ 14:01
    Paul Griffiths
    1

    It was probably my poor explanation ;).

    The help you gave was brilliant and without it I would of struggled, so thank you very much.

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft