Copied to clipboard

Flag this post as spam?

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


  • Magnus Thygesen 8 posts 88 karma points
    Nov 14, 2018 @ 10:36
    Magnus Thygesen
    0

    Dynamic CMS Footer, with own document type

    I need to create a footer with own document type. The person i am creating this site to, should only edit the footer once, and then be applied to all pages.

    My idea was to make a footer document type. Add that document type to a partial view and then i my Master.cshtml file add my partial footer view.

    Something like

    <footer class="section--themed">
        <div class="container">
            <div class="row">
                <div class="col-md-12 ta-center">
                    @Html.Partial("~/Views/Partials/PartialFooter.cshtml")
                </div>
            </div>
        </div>
    </footer>
    

    However, this doesn't work.

    Any ideas? and feel free to ask for more information.

  • Marc Goodson 2138 posts 14321 karma points MVP 8x c-trib
    Nov 14, 2018 @ 22:32
    Marc Goodson
    100

    Hi Magnus

    The template, and partial view will always be executed in the context of the current page the person is visiting.

    What I can't tell from your example above is how you are getting a reference to your footer content.

    Also I'm not sure if you've created a 'footer' composition and added it to all your document types, or just the Homepage, or whether you've created a specific footer 'document type' and so you have a node in the content tree that contains the 'footer' content.

    So if you have a site with structure

    Home - About Us - News - Contact Us - Etc Settings - Footer

    Then in your master page template, you would need to get a reference to the 'Footer' page, and pass this to the PartialFooter partial view, so this partial always worked with the Footer content.

    eg

        <footer class="section--themed">
            <div class="container">
                <div class="row">
                    <div class="col-md-12 ta-center">
    @{
    //use Xpath based on the alias's of each document type in the tree
    IPublishedContent footerContent = Umbraco.TypedContentSingleAtXPath("/root/settings/footer");
    
    }
                        @Html.Partial("~/Views/Partials/PartialFooter.cshtml",footerContent )
                    </div>
                </div>
            </div>
        </footer>
    

    Your PartialFooter view should 'expect' an object of IPublishedContent

    @inherits UmbracoTemplatePage<IPublishedContent>
    @{
    var apropertyfromfooter = Model.Content.GetPropertyValue<string>("propertyfromFooter");
    }
    
    <h2>@apropertyfromfooter</h2>
    

    You could also save this partial executing on every page by using

    @Html.CachedPartial("~/Views/Partials/PartialFooter.cshtml",footerContent,3600)

    to cache the output for 3600 seconds...

  • Magnus Thygesen 8 posts 88 karma points
    Nov 15, 2018 @ 08:42
    Magnus Thygesen
    0

    My structure is like this at the moment

    • Home
      • News
      • About
      • Footer

    My footer document type contains 2 textboxs with alias locationAddress and cvrNumber.

    My partial view looks like this.

    @inherits UmbracoViewPage<IPublishedContent>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    
    <section class="section--themed">
        <div class="container">
            <div class="row">
                <div class="ta-center col-md-4">
                    <p>info rodekors.dk</p>
                    <P>+45 35 25 92 00</P>
                    <P>@Model.GetPropertyValue("locationAddress")</P>
                    <P>2100 København Ø</P>
                    <P>CVR: 20700211</P>
                </div>
                <div class="ta-center col-md-4">
                    <p>Test</p>
                </div>
                <div class="ta-center col-md-4">
                    <p>
                        Test test
                    </p>
                </div>
            </div>
        </div>
    </section>
    

    My master view looks like i posted in the start of the thread

        <footer class="section--themed">
        <div class="container">
            <div class="row">
                <div class="col-md-12 ta-center">
                    @Html.Partial("~/Views/Partials/PartialFooter.cshtml")
                </div>
            </div>
        </div>
    </footer>
    

    And then i also got a template called footer. I am not sure if it is redundent or not. It looks exactly like the partial footer view.

    I hope this clerify how my program looks a bit better. And sorry for how messy it looks, and it is to read. :)

    Marc Goodson, does your solution still works? and do you have any better idea of how to go about it..

    In the end. My footer should contain CMS content and being able to get data from a different database than Umbracos.

  • Magnus Thygesen 8 posts 88 karma points
    Nov 15, 2018 @ 09:33
    Magnus Thygesen
    0

    Thank you @Marc Goodson! It worked!!

  • Marc Goodson 2138 posts 14321 karma points MVP 8x c-trib
    Nov 16, 2018 @ 23:36
    Marc Goodson
    0

    Glad you got it working Magnus!

Please Sign in or register to post replies

Write your reply to:

Draft