Copied to clipboard

Flag this post as spam?

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


  • Martin 18 posts 73 karma points
    Dec 04, 2015 @ 15:34
    Martin
    0

    how do i print out the page name from an ascx file?

    <%= umbraco.library.GetDictionaryItem("dictionaryname") %> that code works,

    so im wondering if there is a similar one, that can pull out current page name?

    <%= umbraco.library.GetSomething %>

    which would result in

    content of dictionary item and then page name written out.

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Dec 04, 2015 @ 20:29
    Marc Goodson
    0

    Hi Martin

    Alot will depend on which version of Umbraco you are using: If you make your usercontrol inherit from the special class UmbracoUserControl

    public partial class MyLovelyUserControl : UmbracoUserControl
    

    Then you will have access to all the Umbraco Helper Methods

    https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/

    and so in your User Control ascx portion you will be able to write:

    <%@ Import Namespace="Umbraco.Web" %>
    <%
        var currentPageId = UmbracoContext.Current.PageId;
        var currentPage = Umbraco.TypedContent(currentPageId);
    %>
    <h1><%=currentPage.Name %></h1>
    

    The currentPage returned above is of IPublishedContent type; you can read about all the available properties on IPublishedContent here:

    https://our.umbraco.org/documentation/Reference/Querying/IPublishedContent/Properties

    If the site is an older version of Umbraco and doesn't have IPublished content etc then if memory serves me correctly the way to get the current node from the content cache in a user control is to use Umbraco NodeFactory eg:

    <%@ Import Namespace="umbraco.NodeFactory" %>
    <%
        var currentNode = Node.GetCurrent();
    %>
    <h2><%=currentNode.Name %></h2>
    

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft