Copied to clipboard

Flag this post as spam?

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


  • javier 64 posts 84 karma points
    Sep 07, 2010 @ 08:03
    javier
    0

    Runaway dropdown navigation URL link and disable

    Hi guys, i was trying to add an some items to my content tree that only act as a parent with 3 sub level, but the parent didn't link  to anything.

    Furthermore, i would like to use some menu items like links to other URL outside website. Is this possible?

    Thank you for your help guys.

     

    regards

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Sep 07, 2010 @ 09:38
    Matt Brailsford
    0

    Hi Javier,

    This is sertainly possible yea.

    For the internal link (parent node linking to first child node) you may want to look into the reserved property alias umbracoRedirect. If you create a property on your doc type of type content picker, with the alias umbracoRedirect then Umbraco will automatically redirect you to the linked node, so if on your parent node you define the property and set it to the first child node beneth it whenever anybody clicks on the parent node it will actually link you to the first child instead.

    External URLs are a little bit trickier. For this I would probably define a property on your doc type of type Textstring with an alias of something like externalUrl. Then in your XSLT for you navigation, when creating the links, check to see if that property is set:

    <a>
    <xsl:attribute name="href">
    <xsl:choose>
    <xsl:when test="string-length(externalUrl) &gt; 0">
    <xsl:value-of select="externalUrl" />
    </xsl:when>
    <xsl:otherwise>

    <xsl:value-of select="umbraco.library:NiceURL(@id)" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:attribute>
    <xsl:value select="@nodeName" />
    </a>

    You may also want to create a macro to drop on the page just incase anybody gets to it directly.

    Hope this gives you some idea on where to start.

    Many thanks

    Matt

  • javier 64 posts 84 karma points
    Sep 07, 2010 @ 10:20
    javier
    0

    Thank you Matt, umbracoRedirect Works very good. And for external links i have found this:

    http://www.neehouse.com/umbraco_cms/packages/redirect.aspx It works on 4.0.4.2.

    And another great thing would be use umbracoRedirect directly to a media file. To get a direct download through main menu or a PDF document. Is this possible now?

    i think no, because u tried everything

     

     

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Sep 07, 2010 @ 10:33
    Matt Brailsford
    0

    Hi Javier,

    I can't say I've tried linking direct to a media item. My initial thoughts would be that it wouldn't work, but by all means give it a try.

    The neehouse macro would also be a good solution. You may need to update it, but as always, there are many ways to do the same thing so whatever works best for you. I have a redirect macro that I use a lot of the time, just create a user control with the following codebehind

    public partial class RedirectControl : System.Web.UI.UserControl
        {
            public bool RedirectToUrl { get; set; }
            public string RedirectUrl { get; set; }
            public bool RedirectToPage { get; set; }
            public int RedirectPage { get; set; }
            public bool RedirectToFirstChild { get; set; }
            public bool IsPermanent { get; set; }

            protected void Page_Init(object sender, EventArgs e)
            {
                if (RedirectToUrl)
                    DoRedirect(RedirectUrl);

                if(RedirectToPage)
                    DoRedirect(FullyQualifiedApplicationPath + umbraco.library.NiceUrl(RedirectPage).TrimStart('/'));

                if(RedirectToFirstChild)
                {
                    var currentNode = Node.GetCurrent();
                    if (currentNode.Children != null && currentNode.Children.Count > 0)
                        DoRedirect(FullyQualifiedApplicationPath + umbraco.library.NiceUrl(currentNode.Children[0].Id).TrimStart('/'));
                }
            }

            protected void DoRedirect(string url)
            {
                if (!IsPermanent)
                {
                    Response.Redirect(url, true); // 302 Found
                }
                else
                {
                    Response.Clear();
                    Response.Status = "301 Moved Permanently";
                    Response.AddHeader("Location", url);
                    Response.End();
                }
            }

            protected string FullyQualifiedApplicationPath
            {
                get
                {
                    var appPath = "";

                    var context = HttpContext.Current;
                    if (context != null)
                    {
                        appPath = string.Format("{0}://{1}{2}{3}",
                            context.Request.Url.Scheme,
                            context.Request.Url.Host,
                            (context.Request.Url.Port == 80) ? string.Empty : ":" + context.Request.Url.Port,
                            context.Request.ApplicationPath);
                    }

                    if (!appPath.EndsWith("/"))
                        appPath += "/";

                    return appPath;
                }
            }
        }

    If you make this into a Macro and define all the fields at the top as properties, you can either drop it in your template or in a richtextarea and set how you want it to redirect.

    I'd still do something in your nav macro to do the external redirect though as that would prevent you from having to go to the actual page first, but this makes for a good backup.

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft