Git Product home page Git Product logo

Comments (6)

rpannekoek avatar rpannekoek commented on June 19, 2024

Current behavior is not intentional, no. The idea is that you can render an Entity Model with another View than what the Entity Model's MVC data says (for whatever reason). This was intended to be a temporary override, though.

Can you further clarify why you want to render the same Entity Model with multiple different (hard-coded) Views, though?

from dxa-web-application-dotnet.

OskarKlintrot avatar OskarKlintrot commented on June 19, 2024

The HTML must look the same as the old site and there is two entities within the same div-tag. This to be able to reuse the CSS. The way I do it now is by simply using @Html.Partial(), so the code looks something like this now:

@model RegionModel
@{ 
    var header = Model.Entities.Single(m => m.MvcData.ViewName == "Header");
}
<div class="header">
  <div class="menu">
    <div class="menu-content">
      @Html.DxaEntity(Model.Entities.Single(m => m.MvcData.ViewName == "Navigation"))
    </div>
    @Html.Partial("_Utility", header)
  </div>
  @Html.Partial("_Logo", header)
</div>

If there is a better way doing it I'm all ears!

from dxa-web-application-dotnet.

rpannekoek avatar rpannekoek commented on June 19, 2024

Interesting! It looks like you need nested Regions. :-)
However, since you're already finding the "Header" Entity by its (original) View name first, would you actually suffer from the quirk/bug that it affects the MVC data of the Entity? That is: will above Region View not work properly if you use @Html.DxaEntity with View override instead of @Html.Partial ?
Or are you also rendering the entity with its original View somewhere else?

from dxa-web-application-dotnet.

OskarKlintrot avatar OskarKlintrot commented on June 19, 2024

I tried that but no, since it is just referencing to the entity it wont help. So the following code wont work:

@model RegionModel
@{
    var header = Model.Entities.Single(m => m.MvcData.ViewName == "Header");
}
<div class="header">
    <div class="menu">
        <div class="menu-content">
            @Html.DxaEntity(Model.Entities.Single(m => m.MvcData.ViewName == "Navigation"))
        </div>
        @Html.DxaEntity(header, "_Utility") @* This changes the MvcData.ViewName *@
    </div>
    @Html.DxaEntity(header, "_Logo") @* Argument Null Exception *@
</div>

This code will work though:

@model RegionModel
<div class="header">
    <div class="menu">
        <div class="menu-content">
            @Html.DxaEntity(Model.Entities.Single(m => m.MvcData.ViewName == "Navigation"))
        </div>
        @Html.DxaEntity(Model.Entities.Single(m => m.MvcData.ViewName == "Header"), "_Utility")
    </div>
    @Html.DxaEntity(Model.Entities.Single(m => m.MvcData.ViewName == "_Utility"), "_Logo")
</div>

from dxa-web-application-dotnet.

rpannekoek avatar rpannekoek commented on June 19, 2024

TSI-1767 (internal issue ID for tracking purposes)

from dxa-web-application-dotnet.

rpannekoek avatar rpannekoek commented on June 19, 2024

Fixed in DXA 1.6.

from dxa-web-application-dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.