I have installed the Multipicker Relations, uComponents packages, and looked at various pages on relations (Hendys Blog and Umbraco TV), but not yet seen any examples in Razor.
I am trying to establish and fetch a bidirectional relationship between members and documents.
I know it would be easier doing this in .NET but would like to hear if any of you have experience with or examples of such relations in Razor.
Using relations with razor
How do I get started using relations in Razor?
I have installed the Multipicker Relations, uComponents packages, and looked at various pages on relations (Hendys Blog and Umbraco TV), but not yet seen any examples in Razor.
I am trying to establish and fetch a bidirectional relationship between members and documents.
I know it would be easier doing this in .NET but would like to hear if any of you have experience with or examples of such relations in Razor.
Well in Razor you can also use C# so you could do something like this:
You'll need to include some more namespaces, but you get the picture :).
Jeroen
Thanks a lot - I'm still new to Razor so that helped a lot :o)
I ended up with this working code;
@using umbraco.cms.businesslogic.relation;
@using umbraco.cms.businesslogic.member;
@{
RelationType relationType = RelationType.GetByAlias("myRelationType");
Relation[] relations = Relation.GetRelations(Model.Id, relationType);
Member member;
<h2>Relations</h2>
foreach (Relation relation in relations)
{
member = new Member(relation.Child.Id);
<p>@member.Text</p>
}
}
Glad you got it working. If you want to access member information maybe you should have a look at this topic: http://our.umbraco.org/forum/developers/extending-umbraco/27626-Accessing-Member-Information
Jeroen
is working on a reply...