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.
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
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 :-)
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 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...
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.
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
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
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 theuComponents.DataTypes.dll
anduComponents.Legacy.dll
files. Then all the other components should work fine - including all the XSLT extensions :-)Good luck!
Cheers,
- Lee
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:
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
Hi Allan,
What happens when you call
umbraco.library:GetCurrentMember()
directly?Try this:
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
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
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
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
... since it's lunch - let me look into it (no promises though) ;-)
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.Then within your XSLT, you will need to add the namespace reference for
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:
Fingers crossed that will work for you.
Good luck!
Cheers,
- Lee
Thanks very much Lee. I have to dash out now, but will try this later today.
Much appreciated
Allan
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
Hi Allan,
The quick and dirty fix is to add a try/catch around the code, like this:
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
Hi Lee
Once again, that works great - very many thanks!
Allan
You're welcome. Hopefully the underlying bug in Umbraco will be fixed in a future release.
Cheers,
- Lee
is working on a reply...