Using Umbraco v11.2.1 currently. In the same way the backend has access to relationships as shown in the screenshot below, is it possible to query these relationships on the frontend via Razor .cshtml pages?
(there is a caveat that doing so hits the database, and for page speed performance you don't always want to do that on every request, so the suggestion is to cache things if you can to avoid the database from being hit! - depending on what you are doing that might just mean caching a partial view or using Cache Tag Helper).
In terms of using the RelationsService inside a View/Template - you can do so by 'injecting it' at the top of the view file (or in your _ViewImports.cshtml if you are using it in multiple Views)
Access Relationships/References in .cshtml pages
Using Umbraco v11.2.1 currently. In the same way the backend has access to relationships as shown in the screenshot below, is it possible to query these relationships on the frontend via Razor .cshtml pages?
Hi Mark
There is a general overview of Relations here
https://docs.umbraco.com/umbraco-cms/fundamentals/data/relations/
but it's not super clear how you would query them in code!
You would use the RelationsService to do so https://docs.umbraco.com/umbraco-cms/reference/management/services/relationservice
(there is a caveat that doing so hits the database, and for page speed performance you don't always want to do that on every request, so the suggestion is to cache things if you can to avoid the database from being hit! - depending on what you are doing that might just mean caching a partial view or using Cache Tag Helper).
In terms of using the RelationsService inside a View/Template - you can do so by 'injecting it' at the top of the view file (or in your _ViewImports.cshtml if you are using it in multiple Views)
https://docs.umbraco.com/umbraco-cms/implementation/services#accessing-management-services-and-helpers-in-a-template-view
regards
Marc
is working on a reply...