Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • kyle 49 posts 240 karma points
    Dec 03, 2021 @ 09:52
    kyle
    0

    How to create Dynamic Master Template Content?

    Hello everyone!

    I have a master template that contains a navbar and a footer and it renders the navbar and footer content from a "home page" document type.

    I also have a home page template that is a child of the master template and the home page looks clean and everything gets rendered...

    I have then gone on and created a second page(doctype with a template) That template also inherits from the master...

    this is where the problem comes in, when I want to view that second page I get a compilation error because it's a child of the master, the master template tries to render content that is sitting in the home page doctype...

    how can I resolve this issue?

    How can I make my master template content dynamic? and still, have child templates under the master template?

    I hope this makes sense, it's a really big problem for me that I NEED to solve urgently...

    Thank you

  • kyle 49 posts 240 karma points
    Dec 03, 2021 @ 10:11
    kyle
    0

    At this moment in the master i'm using this to render:

    <h1>@Model.Value("alias")</h1>
    

    is there some way I can access the homepage content without saying "model"?

    something along this line:

    <h1>HomePage.headerText</h1>
    

    ?

  • Ibrahim Nada 21 posts 167 karma points c-trib
    Dec 06, 2021 @ 12:22
    Ibrahim Nada
    0

    okay ,

    Generally speaking , anything is related to home page should be in the home page template or at least but it in a partial view.

    but In your case if u need to render things and some times not

    you should make an if statement to wrap up any thing should make an error appear like the following :

    @if(@Model.Value("alias") != null)
    {
     <h1>@Model.Value("alias")</h1> 
    }
    

    this way it will only be render when it has a value ....

    hope that helped

Please Sign in or register to post replies

Write your reply to:

Draft