Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 12 2020 01:41

    jtkech on patch-1

    (compare)

  • Apr 12 2020 01:39

    jtkech on patch-1

    Update ZoneShapes.cs (compare)

Jasmin Savard
@Skrypt
You mean how to login?
23 replies
Niraj Soni
@ns8482e
Is there built-in way to display Numeric field as currency? i.e prefixed with $?
31 replies
Rustem
@rserj
image.png
21 replies
Hello, can I display Nested/Conditional fields somthing like this?
Steven Spits
@netwavebe

Is there a way in OC to get the html of a content item using a specific displayType in a controller?
I tried this:

var productShape = await _contentItemDisplayManager.BuildDisplayAsync(product, this, "Detail");
var productHtml = await displayHelper.ShapeExecuteAsync(productShape);

This works, but productHtml also includes the theme html, which I do not want. Any ideas?

Niraj Soni
@ns8482e
check productShape.Content it will have html you need
Jasmin Savard
@Skrypt
What you mean by theme html? You mean the admin theme styles?
The BuildDisplayAsync will use whatever templates you implemented in your own theme too.
Small screenshot would help
Sébastien Ros
@sebastienros
@netwavebe definitely there is a way ... trying to remember
Sébastien Ros
@sebastienros
I know !!!!!
Steven Spits
@netwavebe
@Skrypt productHtml includes the frontend theming (a complete page) but I want only the fragment rendered by one product.
@sebastienros I'm all ears! :-D
Sébastien Ros
@sebastienros
we had [Themed(false)] on the action in O1, there is something like this also in OC but can't find it
maybe it's done in a more clever way, but I don't remember, and that must be me who implemented it, such a shame
Niraj Soni
@ns8482e
If you are using MVC, you can set Layout = null
Steven Spits
@netwavebe
@sebastienros I found this OrchardCMS/OrchardCore#5687 but I'm not sure what you mean by saying just use the shape you created.
Sébastien Ros
@sebastienros
right, the issue is that the shape you use is created by BuildDisplay, like in the sample I provided on the issue
so this shape will have the layout on it, because that's what content item shapes do, inject stuff in layout zones
if you use Summary, you don't have the Layout I assume?
Steven Spits
@netwavebe
Let me try this
Looks the same
Sébastien Ros
@sebastienros
got an idea. In your controller, pass the shape to the view as the model
in the view call await DisplayAsync(Model)
but also add this at the top: @{ ThemeLayout = null; }
Steven Spits
@netwavebe
@sebastienros That would probably work, but is not useful in my case. I'm trying to do this in an api controller. Need to return JSON: products with data and some html fragments.
Sébastien Ros
@sebastienros
I made a graphql endpoint for rendering content items, maybe the solution is there
can't remember if there was layout or not included in it
looking for it...
Niraj Soni
@ns8482e
Create theme selector based on RequestPath
Steven Spits
@netwavebe
@ns8482e Feels really hacky. It shouldn't be this hard to get the html fragment a single content item would render (assuming it's not using zone/placement/...).
Sébastien Ros
@sebastienros
I believe the theme is not applied if it's not a controller. Can you try putting your code in a middleware endpoint?
or we might have to implement this Themed(false) attribute. Not hard though, it would set a scoped property that is checked where the layout is applied. Or it could use a Theme selector and this attribute
Steven Spits
@netwavebe
@sebastienros Moving it to a service and injecting all services is not enough. But of course it's still the controller calling this service.
@sebastienros Much harder than I anticipated, might be better to look at other solutions (send everything as data and make a similar template in Angular).
Niraj Soni
@ns8482e
another option is to implement ActionFilter
and assign Theme to null for RazorViewFeature
Jasmin Savard
@Skrypt
@sebastienros Yes it renders the entire layout
The GraphQL render method
Niraj Soni
@ns8482e
I have same issue with BlazorServer
Jasmin Savard
@Skrypt
So BuildDisplayAsync does what I thought. It renders all the small pieces from .cshtml templates. So, it's just about rendering the HTML and Body tags or not.
But at the same time then, some things might not work if you want a script rendered at header.
Because we render these scripts and styles on the header of the page.
So, returning the content of the BuildDisplayAsync without theming or scripts but if you have scripts that are rendered at head then you don't have a Layout to include them after the Body tag for example.
So, I guess in that case the best option is to use an alternate Layout
Jasmin Savard
@Skrypt
Which doesn't contain any HTML and Body tag.
Jasmin Savard
@Skrypt
Okay then from a GraphQL API call then you can parse the DOM result and keep only everything inside the Body tag since you might be requesting this from a javascript call.
Or we should be able to pass a param that says use X layout.
Jasmin Savard
@Skrypt
I think @sebastienros knows what to do here