Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Jul 16, 2014 @ 15:04
    Steve
    0

    Confused About Nested Templates

    I need a new layout based on a parent of a child node template, but I am created the node at the child's level and it is inheriting content that I don't want in the template. Is there a way to override content that is added in at the parent template level within a child of that parent?

  • Dan Lister 416 posts 1974 karma points c-trib
    Jul 24, 2014 @ 17:22
    Dan Lister
    0

    Hi Steve,

    Assuming you are using razor for your templates/views, you could use sections. For example, your parent template could have the following to see if a section has been defined by any it's children. If not, default content could be displayed.

    @{
        if (IsSectionDefined("Footer")) 
        {
            RenderSection("Footer");
        }
        else 
        { 
            <div>Default footer content.</div>   
        }
    }
    

    If you did not want default content within your child template, you could add the following section to your child template.

    @section Footer 
    {
        <div>Override footer content.</div> 
    }
    

    Thanks, Dan.

Please Sign in or register to post replies

Write your reply to:

Draft