Copied to clipboard

Flag this post as spam?

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


  • Tom Bruce 122 posts 506 karma points
    Oct 26, 2017 @ 11:08
    Tom Bruce
    0

    How to display the page title from a partial page

    Hi, can you display the page title from a Partial-page. I would like to set the page title from the Partial-page.

    I have the following code within my master layout

    @Umbraco.Field("title", altFieldAlias: "pageName")
    

    And within my Partial-page I have the following code

    if (ApplyingChk == true){ <title> title 1 </title>} else { <title> title 2 </title>}
    

    But I keep getting the page title instead of the Partial-page title. I hope this makes sense?

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Oct 26, 2017 @ 11:17
    Michaël Vanbrabandt
    0

    Hi Tom,

    in the way you are describing you now set the title tag twice, once in the master page and once in the partial view correct?

    Where do you call the partial view, is it on the master page?

    If so then remove the @Umbraco.Field("title", altFieldAlias: "pageName") and place the call to your partial view for rendering the title here.

    Then in your partial view you can set the correct title tag based on your conditions.

    Another solution could be using a @helper class on your master page for rendering the title tag, then you won't need to call a partial view.

    Hope this helps

    /Michaël

  • Tom Bruce 122 posts 506 karma points
    Oct 26, 2017 @ 13:12
    Tom Bruce
    0

    Hi Michael, I call the the partial view from a template like so;

        @{ Html.RenderAction("RenderApplicantDetails", "Applicant");}
    

    I have removed the @Umbraco.Field("title", altFieldAlias: "pageName") from the master page and placed it into the template page, but I keep getting the page title.

    How do I render the title that's on the partial-page?

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Oct 26, 2017 @ 13:24
    Michaël Vanbrabandt
    0

    Hi Tom,

    can you share the code from your template / partial view?

    /Michaël

  • Tom Bruce 122 posts 506 karma points
    Oct 26, 2017 @ 13:56
    Tom Bruce
    1

    Hi Michael, I think I found the answer by placing the following code into my partial page

    @{ ViewBag.Title = "About Us From The Partial View"; }

    <script type="text/javascript">
    document.title = "@ViewBag.Title";
    

Please Sign in or register to post replies

Write your reply to:

Draft