Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DrewBrasher
Copy link
Contributor

@DrewBrasher DrewBrasher commented Nov 20, 2024

This was discussed in Discord

@@ -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
Copy link
Member

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

Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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.

Comment on lines +48 to +49
@using OrchardCore
@inject IOrchardHelper Orchard
Copy link
Member

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

public IOrchardDisplayHelper Orchard
{
get
{
if (_orchardHelper == null)
{
EnsureDisplayHelper();
_orchardHelper = new OrchardDisplayHelper(Context, _displayHelper);
}
return _orchardHelper;
}
}

Copy link
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants