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>
}
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...
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
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).
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.
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 ...
}
anybody please
Hi Naveed,
When your macro renders to the screen, if you inspect source, what html is generated?
Nik
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...
Thanks
Nav
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:
Then examine Model.MacroParameters to ensure it has values.
If you aren't using Visual Studio try putting
after the line mentioned above to see what it renders out.
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
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).
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..
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.
Hi Nik,
I have tried that unfortunately still nothing :-(
is working on a reply...
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.