Copied to clipboard

Flag this post as spam?

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


  • Allan James 20 posts 40 karma points
    Feb 07, 2012 @ 03:52
    Allan James
    0

    Call me crazy but this isn't something too much to ask of a CMS

    So, on a page where a document type has a section defined as a RTF section AND there are some links to documents within the Media files.... but some of the links to the files must ONLY be shown if the user is logged in.

    How can I hide some of the links when the user is NOT logged in?

    Allan

  • Doron 6 posts 28 karma points
    Feb 07, 2012 @ 07:11
    Doron
    0

    I haven't tried it myself, buy why not create a macro that wraps a server control or user control that renders the link only if a member is logged in?

     

    you can then enable this macro for the editor

    Your control should be something like:

     

    public class MembersLink : Control
        {
            public int MediaId { get; set; }
            public string Text { get; set; }

            protected override void Render(HtmlTextWriter writer)
            {
                if (umbraco.cms.businesslogic.member.Member.GetCurrentMember() != null)
                {
                    Media media = new Media(MediaId);

                    writer.AddAttribute(HtmlTextWriterAttribute.Href, media.getProperty("umbracoFile").Value.ToString());
                    writer.RenderBeginTag(HtmlTextWriterTag.A);
                    writer.Write(Text);
                    writer.RenderEndTag();
                }

            }
        }

  • Markus Johansson 1938 posts 5866 karma points MVP 2x c-trib
    Feb 07, 2012 @ 07:37
    Markus Johansson
    0

    Or go with a Razor-macro that checks if the user is logged on. You could use inline razor to do it in a template if you want to.

  • Nigel Wilson 945 posts 2077 karma points
    Feb 07, 2012 @ 07:57
    Nigel Wilson
    0

    And to add to the replies...

    You can also check for a member being logged in via XSLT.

    <xsl:if test="umbraco.library:IsLoggedOn() = 1">
    ...
    </xsl:if>

    So 3 different coding techniques to achieve the same results - and why do they say Umbraco is brilliant... 

    Cheers

    Nigel

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 07, 2012 @ 09:15
    Jeroen Breuer
    0

    If you want to protect media files you can use Media Protect

    Jeroen

  • Allan James 20 posts 40 karma points
    Feb 07, 2012 @ 20:07
    Allan James
    0

    Thanks everyone for your help.... I guess what I was wondering was can this be done at the Content side of things (within the Ruch Text Editor portion) - On the template side I know this is possible.

    @Jeroen: If I use Media Protect - would the link in the Rich Text just not show up? Is that how it works... I can read the material and see..

     

    Thanks,

     

    Allan

Please Sign in or register to post replies

Write your reply to:

Draft