Copied to clipboard

Flag this post as spam?

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


  • Naveed Ali 161 posts 426 karma points
    Apr 26, 2016 @ 15:36
    Naveed Ali
    0

    Button link help!

    I have a the following code which is a macro link.

    I am using umbraco v7

    It all displays fine BUT the button does not work.. I have tried changing the href to all sorts but still to no avail..It just opens up to the same current page or reloads the current page

    any help would be appreciated ...

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        bool show = true;
        var url = Model.MacroParameters["externalLinks"];
        if (url == null)
        {
            var targetNode = Umbraco.Content(Model.MacroParameters["target"]);
            url = targetNode.Url;
    
            if (targetNode.nodeTypeAlias == "File")
            {
                var mediaNode = Umbraco.Content(Model.MacroParameters["target"]);
                if (wodc.code.UmbracoHelpers.isRecycled(mediaNode))
                {
                    show = false;
            }
        }
    }
    var targetString = Model.MacroParameters["showInCurrentWindow"] == "1" ? "_self" : "_blank";
    var linkTitle = Model.MacroParameters["linkText"];
    if (linkTitle == string.Empty)
    {
        var mediaNode = Umbraco.Content(Model.MacroParameters["target"]);
        linkTitle = mediaNode.Name;
    }
    
    
    if (show)
    {
        var targetNode = Umbraco.Content(Model.MacroParameters["target"]);
        var element = "<{0}>{1}</{0}>";
        var el = "h4";
        //if (!String.IsNullOrEmpty(Parameter.renderAsElement))
        //{
        //    el = Parameter.renderAsElement;
        //}
        <a class="btn content-link lrg" target="@url" href="@url">@Html.Raw(@String.Format(element, el, linkTitle))</a>
    }
    

    }

  • Naveed Ali 161 posts 426 karma points
    Apr 27, 2016 @ 10:31
    Naveed Ali
    0

    anybody please

  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    Apr 27, 2016 @ 13:19
    Nik
    0

    Hi Naveed,

    When your macro renders to the screen, if you inspect source, what html is generated?

    Nik

  • Naveed Ali 161 posts 426 karma points
    Apr 27, 2016 @ 13:25
    Naveed Ali
    0

    Hi Nik,

    this is what is generated, as you can probably tell the target and href are blank.. whichi i believe is the issue it is not picking up the macro parameter target as a URL...

    <a class="btn content-link lrg" target="" href=""><h4>Council Tax</h4></a>
    

    Thanks

    Nav

  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    Apr 27, 2016 @ 14:00
    Nik
    0

    Have you verified that the macro parameters are populated in the first place?

    If you are using Visual Studio, I'd put a breakpoint on this line:

    var url = Model.MacroParameters["externalLinks"];
    

    Then examine Model.MacroParameters to ensure it has values.

    If you aren't using Visual Studio try putting

    <div>@url</div> 
    

    after the line mentioned above to see what it renders out.

  • Naveed Ali 161 posts 426 karma points
    Apr 27, 2016 @ 14:11
    Naveed Ali
    0

    Hi Nik,

    yes I have already done that and all the parameters are successfully coming through just on the line on the button the target and url do not come through I just get empty fields

  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    Apr 27, 2016 @ 14:28
    Nik
    0

    So if you render out @url not in the link bit, then it renders out the correct url? (sorry just trying to clarify as I can't see anything wrong with the code directly).

  • Naveed Ali 161 posts 426 karma points
    Apr 28, 2016 @ 08:40
    Naveed Ali
    0

    Hi Nik,

    I have tried just @url..and there is nothing coming through ..which is very odd as on the var url there is data in there..

    seems to be the way I am outputting it on the button is not correct..

  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    Apr 28, 2016 @ 13:40
    Nik
    0

    This might seem like a bit off an off the cuff idea, but try changing the name of the variable, just in case @url is trying to something specific. I know @Url (capital U) is a key helper.

  • Naveed Ali 161 posts 426 karma points
    Apr 28, 2016 @ 13:46
    Naveed Ali
    0

    Hi Nik,

    I have tried that unfortunately still nothing :-(

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies