-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added using statement to the Razor Helper usage example #17040
base: main
Are you sure you want to change the base?
Conversation
@@ -44,6 +44,7 @@ Many extensions methods are available in Razor with `@Orchard`. | |||
If you want to use an extension method in a view, you can inject an `IOrchardHelper` named `Orchard` at the top of your file: | |||
|
|||
```csharp | |||
@using OrchardCore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is right if it's not in the _ViewImports.cshtml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not there by default.
@@ -44,6 +44,7 @@ Many extensions methods are available in Razor with `@Orchard`. | |||
If you want to use an extension method in a view, you can inject an `IOrchardHelper` named `Orchard` at the top of your file: | |||
|
|||
```csharp | |||
@using OrchardCore | |||
@inject OrchardCore.IOrchardHelper Orchard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for OrchardCore.
here then, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did end up adding mine to the _ViewImports.cshtml
instead of adding it here. Should I remove this from the usage examples and just write a comment that you might need to add the using statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, the using
is good, I'm talking about having@inject IOrchardHelper Orchard
instead of @inject OrchardCore.IOrchardHelper Orchard
, since you already import the namespace.
But otherwise yeah, you could clarify with e.g.:
// You can also put this into a _ViewImports.cshtml file so it's applied to all templates.
@using OrchardCore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, I misunderstood. I will remove the OrchardCore.
and add the comment.
@@ -44,6 +44,7 @@ Many extensions methods are available in Razor with `@Orchard`. | |||
If you want to use an extension method in a view, you can inject an `IOrchardHelper` named `Orchard` at the top of your file: | |||
|
|||
```csharp | |||
@using OrchardCore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not there by default.
@using OrchardCore | ||
@inject IOrchardHelper Orchard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already injected in OC, if you are using OrchardCore.DisplayManagement.Razor.RazorPage
from within _ViewImports
OrchardCore/src/OrchardCore/OrchardCore.DisplayManagement/Razor/RazorPage.cs
Lines 95 to 107 in 8ffc51a
public IOrchardDisplayHelper Orchard | |
{ | |
get | |
{ | |
if (_orchardHelper == null) | |
{ | |
EnsureDisplayHelper(); | |
_orchardHelper = new OrchardDisplayHelper(Context, _displayHelper); | |
} | |
return _orchardHelper; | |
} | |
} |
This pull request has merge conflicts. Please resolve those before requesting a review. |
This was discussed in Discord