Copied to clipboard

Flag this post as spam?

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


  • trfletch 598 posts 604 karma points
    Jul 21, 2009 @ 13:01
    trfletch
    0

    Restricting some page content unless logged on

    Hi,

    I have created a template that has two text fields, on is called non-members text and the other is called members text, Is it possible to have only the non-members text showing unless the user is logged on? I would Ideally like a message that says to view the rest of the article please log on. The content must not be shown at all and cannot be just in a hidden div because it would be visible in the source code. The template is as follows, I'm hoping there is some sort of member control that can be put round the memberstext div that will not show it unless the user is logged on and will instead show a link to the login page or something similar:

    <div id="nonmemberstext">
    <umbraco:Item field="nonmemberstext" runat="server"></umbraco:Item>
    </div>
    <div id="memberstext">
    <umbraco:Item field="memberstext" runat="server"></umbraco:Item>
    </div>
  • Petr Snobelt 923 posts 1535 karma points
    Jul 21, 2009 @ 13:35
    Petr Snobelt
    1

    Create simple macro and use umbracolibrary:isloggedon

    something like this

    <xsl:choose>
     <xsl:when test="umbraco.library:IsLoggedOn()">
      <xsl:value-of select="data [@alias = 'memberstext']" />
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="data [@alias = 'nonmembersText']" />
     </xsl:otherwise>
    </xsl:choose>

    or use umbraco.library:IsLoggedOn() directly in template with <% %>

  • trfletch 598 posts 604 karma points
    Jul 21, 2009 @ 16:25
    trfletch
    0

    Thanks for the reply Petr, when I tried to create this XLST file I get the following error:

    System.NullReferenceException: Object reference not set to an instance of an object. 
    at umbraco.BusinessLogic.StateHelper.GetCookieValue(HttpContext context, String key)
    at umbraco.BusinessLogic.StateHelper.HasCookieValue(String key)
    at umbraco.cms.businesslogic.member.Member.CurrentMemberId()
    at umbraco.cms.businesslogic.member.Member.IsLoggedOn()
    at umbraco.library.IsLoggedOn()
  • trfletch 598 posts 604 karma points
    Jul 21, 2009 @ 18:13
    trfletch
    0

    Ok I have solved it myself, I needed to add = 1 to the IsloggedOn statement as follows:

    <xsl:choose>
     <xsl:when test="umbraco.library:IsLoggedOn() = 1">
     <div id="nonmemberstext">
     <xsl:value-of select="$currentPage/data [@alias = 'nonmemberstext']" disable-output-escaping="yes"/>
     </div>
     <div id="memberstext">
     <xsl:value-of select="$currentPage/data [@alias = 'memberstext']" disable-output-escaping="yes"/>
     <br/>
     </div>
     </xsl:when>
     <xsl:otherwise>
     <div id="nonmemberstext">
     <xsl:value-of select="$currentPage/data [@alias = 'nonmemberstext']" disable-output-escaping="yes"/>
     </div>
     <p>To view full article please login</p>
     </xsl:otherwise>
    </xsl:choose>
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies