Copied to clipboard

Flag this post as spam?

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


  • Allan Hawkey 221 posts 292 karma points
    Feb 21, 2015 @ 11:49
    Allan Hawkey
    0

    GetUniqueId in Umbraco 7.2.1

    I use uComponents in some Umbraco 4.11.10 sites and am looking at upgrading to 7.2.1.

    In particular, I use ucomponents.members:GetUniqueId extensively in my sites in my xslt files, so was wondering how best to obtain the member IDs in 7.2.1 if uComponents isn't available??

    I'm new to 7.2.1, so appreciate any guidance on how best to replicate this in the new version.

    Thanks
    Allan

  • Dennis Aaen 4125 posts 16747 karma points admin hq c-trib
    Feb 21, 2015 @ 13:33
    Dennis Aaen
    0

    Hi Allan,

    No the Components isn't available for Umbraco 7, but instead of the Components we have the nuPickers package which you can find here: https://our.umbraco.org/projects/backoffice-extensions/nupickers

    So try to have a look at this package and see if there is something that match your usecase. And the documentation for nuPickers can you find here: https://github.com/uComponents/nuPickers/wiki

    Hope this helps,

    /Dennis

  • Lee Kelleher 3632 posts 12933 karma points admin core mvp c-trib
    Feb 21, 2015 @ 15:02
    Lee Kelleher
    0

    Hi Allan,

    You can still use uComponents with v7.x - only the legacy data-type editors don't work any more, everything else should be fine :-)

    A couple of things to note, when you install uComponents package via the v7 back-office, it will throw a big old YSoD error saying about the uComponents.DataTypes assembly. What you need to do is go to your /bin folder and delete both the uComponents.DataTypes.dll and uComponents.Legacy.dll files. Then all the other components should work fine - including all the XSLT extensions :-)

    Good luck!

    Cheers,
    - Lee

  • Allan Hawkey 221 posts 292 karma points
    Feb 24, 2015 @ 23:43
    Allan Hawkey
    0

    Hi Lee

    That's really helpful - managed to follow your steps and get past the YSoD.  However, I'm still struggling to get the relevant information presented.

    In my old XSLT files (in Umbraco 4.11), I had:

    <xsl:value-of select="ucomponents.members:GetUniqueId(umbraco.library:GetCurrentMember()/@id)"/>

    Any suggestions for how to replicate this in Umbraco 7?

    Dennis - thanks also for your reply, though I can't see anything in nuPickers which would help me with this - have I missed something?

    Thanks
    Allan

  • Lee Kelleher 3632 posts 12933 karma points admin core mvp c-trib
    Feb 25, 2015 @ 12:12
    Lee Kelleher
    0

    Hi Allan,

    What happens when you call umbraco.library:GetCurrentMember() directly?

    Try this:

    <xmp><xsl:copy-of select="umbraco.library:GetCurrentMember()" /></xmp>
    

    That will dump out the XML for the member.

    I'm wondering if that function call is doing something differently in v7.x?

    Thanks,
    - Lee

  • Allan Hawkey 221 posts 292 karma points
    Feb 25, 2015 @ 12:48
    Allan Hawkey
    0

    Hi Lee

    OK - I added this to an XSLT file and added it to a template via a macro in 7.2 - there was no output when logged in.  However, when not logged in, it returned: "No current member exists (best practice is to validate with 'isloggedon()' prior to this call)".  So it appears to recognise the call, but not return the XML??

    I tried the same in one of my old 4.11 sites, and the XML was returned ok (though not the UniqueID that I'm after, but I guess that's a further step via uComponents...)

    So something certainly seems different with v7.2??

    Thanks
    Allan

  • Lee Kelleher 3632 posts 12933 karma points admin core mvp c-trib
    Feb 25, 2015 @ 13:01
    Lee Kelleher
    0

    Hi Allan,

    I had a quick look in the Umbraco bug tracker and found this issue:

    http://issues.umbraco.org/issue/U4-5073 - it seems that GetCurrentMember has been broken since v6.2.

    It is worth voting up the issue and leaving a comment on the ticket.


    I'm afraid I don't have another solution for you, unless you know C# and can code up a workaround?

    Cheers,
    - Lee

  • Allan Hawkey 221 posts 292 karma points
    Feb 25, 2015 @ 13:21
    Allan Hawkey
    0

    Hmmm, that's a real pain!  No, I won't be able to code that up - any suggestions for where I might find someone who could help me with that?

    Thanks
    Allan

  • Lee Kelleher 3632 posts 12933 karma points admin core mvp c-trib
    Feb 25, 2015 @ 13:59
    Lee Kelleher
    0

    ... since it's lunch - let me look into it (no promises though) ;-)

  • Lee Kelleher 3632 posts 12933 karma points admin core mvp c-trib
    Feb 25, 2015 @ 14:10
    Lee Kelleher
    100

    OK, here goes...

    Copy this code snippet to a file (can it OurUmbracoMembers.cs, but you can call it anything) and put it in your /App_Code folder.

    namespace Our.Umbraco
    {
        [umbraco.XsltExtension("our.umbraco.members")]
        public class Members
        {
            public static string GetCurrentMemberUniqueId()
            {
                var currentMemberId = umbraco.cms.businesslogic.member.Member.CurrentMemberId();
    
                if (currentMemberId > 0)
                {
                    return uComponents.XsltExtensions.Members.GetUniqueId(currentMemberId);
                }
                else
                {
                    return "";
                }
            }
        }
    }
    

    Then within your XSLT, you will need to add the namespace reference for our.umbraco.members:

    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        xmlns:our.umbraco.members="urn:our.umbraco.members"
        exclude-result-prefixes="msxml umbraco.library our.umbraco.members">
    

    Note - I'm not sure if you have other namespace references in your XSLT... basically just add the new one for our.umbraco.members in there.

    Then, give it a try:

    <xsl:value-of select="our.umbraco.members:GetCurrentMemberUniqueId()" />
    

    Fingers crossed that will work for you.

    Good luck!

    Cheers,
    - Lee

  • Allan Hawkey 221 posts 292 karma points
    Feb 25, 2015 @ 14:34
    Allan Hawkey
    0

    Thanks very much Lee.  I have to dash out now, but will try this later today.

    Much appreciated

    Allan

  • Allan Hawkey 221 posts 292 karma points
    Feb 25, 2015 @ 18:52
    Allan Hawkey
    0

    Lee

    Thanks so much for that - works great and does what I need.

    Only slight wrinkle is that when I save the XSLT file, it gives an error (I think it's trying to find my current member unique ID for my back end USER login!).  I can bypass that by ticking "skip testing" on the properties tab, but if there's an easy way to enable that to save without any errors, that would be great...

    Cheers

    Allan

  • Lee Kelleher 3632 posts 12933 karma points admin core mvp c-trib
    Feb 26, 2015 @ 10:35
    Lee Kelleher
    0

    Hi Allan,

    The quick and dirty fix is to add a try/catch around the code, like this:

    namespace Our.Umbraco
    {
        [umbraco.XsltExtension("our.umbraco.members")]
        public class Members
        {
            public static string GetCurrentMemberUniqueId()
            {
                try
                {
                    var currentMemberId = umbraco.cms.businesslogic.member.Member.CurrentMemberId();
    
                    if (currentMemberId > 0)
                    {
                        return uComponents.XsltExtensions.Members.GetUniqueId(currentMemberId);
                    }
                }
                catch { /* do nothing */ }
    
                return "";
            }
        }
    }
    

    From a coding perspective this is considered quite bad, as the underlying error is hidden away - but for your case it works around the problem of saving XSLT files in the back-office.

    Cheers,
    - Lee

  • Allan Hawkey 221 posts 292 karma points
    Feb 26, 2015 @ 10:48
    Allan Hawkey
    0

    Hi Lee

    Once again, that works great - very many thanks!

    Allan

  • Lee Kelleher 3632 posts 12933 karma points admin core mvp c-trib
    Feb 26, 2015 @ 10:49
    Lee Kelleher
    0

    You're welcome. Hopefully the underlying bug in Umbraco will be fixed in a future release.

    Cheers,
    - Lee

Please Sign in or register to post replies

Write your reply to:

Draft