Copied to clipboard

Flag this post as spam?

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


  • Tom 28 posts 48 karma points
    Sep 19, 2013 @ 09:27
    Tom
    0

    Add new property to external link

    Hi

    Our website has a carousel of images (Home Carousel Items), and all of these can only link to an internal node on the same domain. I'm trying to get one to link to an external site, and I'm trying to add a new property to the Home Carousel Item in the Settings tab. But I can't find an option for adding a property that will allow me to link to an external site. Any ideas?

  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 19, 2013 @ 09:36
    Fuji Kusaka
    0

    Hi Tom,

    You could simply make use of a textString where you will add the Url of the external link.

    If you are planning to use razor then you have to do something like this

    var externalUrl = (Model.HasValue("externalUrlAlias"))? @model.externalUrlAlias : @model.Url ;
    string targetUrl = (Model.HasValue("externalUrlAlias")) ? "target=_blank" : "target=_self";

    <li><a href="@externalUrl" target="@targetUrl">....</a></li>

    hope this helps

     

    //fuji

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 19, 2013 @ 09:37
    Dennis Aaen
    1

    Hi Tom.

    One solution could be to use some of the packages there is to Umbraco. For your issue one package you could try is the uCompoents URL picker, with this you should be able to link external. The documentation for the URL picker can be found here: http://ucomponents.codeplex.com/wikipage?title=UrlPicker.

    I must mention that I havenĀ“t tried the URL picker myself, but have seen it suggested several times, when you have to create a external link.

    I Hope this could be a solution to you.

    /Dennis

  • Tom 28 posts 48 karma points
    Sep 20, 2013 @ 07:53
    Tom
    0

    Hi guys. Thanks for this. Fuji, I'm not at all familiar with .NET, very much a noob, and so far I've only used the Umbraco backend without diving into the source files. I'm not sure what Razor is - is it a package? If you could elaborate on where I might include that code snippet I'd be grateful.

     

    Dennis, I think that could be a good option, only our install of Umbraco is 4.0.4.2 - quite old - but my company doesn't want to upgrade at this stage. I tried to install Contour recently (a legacy version, as the current version wasn't compatible with our version of Umbraco), and it busted the whole site; apparently it dumped a .dll file somehwere that conflicted with a file Google Analytics installed somehwere, and the result was a disaster! It's frustrating using an old version of Umbraco but I'm too scared to try installing another plugin....

  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 20, 2013 @ 08:49
    Fuji Kusaka
    0

    Hi Tom,

    Can you tell us more on your project and how you are using umbraco to make your carousel ?

    Razor is a so called "View engine" for ASP.NET MVC...and can work with ASP.NET web forms

    Basically it's another option you can use to fetch data.

    You can read some post here about razor and umbraco :
    http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx
    http://www.cultiv.nl/blog/2011/2/16/how-to-use-razor-in-umbraco

  • Tom 28 posts 48 karma points
    Sep 20, 2013 @ 09:12
    Tom
    0

    Thanks Fuji. I'll read up on those links, and then next week get back to you with more info on the Carousel and how it integrates into our backend (it's Friday afternoon now, and home time!)

     

    Cheers for all your help...

  • Steve 472 posts 1216 karma points
    Apr 14, 2014 @ 22:48
    Steve
    0

    Fugi,

    I was looking at your code to check for the property "externalUrlAlias". I have a "URL" property on externalLink doctype, so how might I implement your code with my current doctype?

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 15, 2014 @ 06:02
    Fuji Kusaka
    0

    Hi Steve,

    What do you mean by how to implement with your current docType? Can you show your current code ?

     

  • Steve 472 posts 1216 karma points
    Apr 15, 2014 @ 14:26
    Steve
    0

    Sorry Fuji, here is my code.

    @{
    var page = Model.AncestorOrSelf(3).Children;
    
    <ul>
    @foreach (var subPage in page) {
          var style = subPage.IsDescendantOrSelf(Model) ? "class=active" : "";
    
    
        <li @style ><a href="@subPage.Url">@subPage.Name</a>
    @if(subPage.Children.Any() && subPage.IsAncestorOrSelf(Model)){ 
        <ul class="academics-items">
            @foreach (var item in subPage.Children.Where("Visible")) {
    var childActive = item.IsAncestorOrSelf(Model) ? "class=active" : "";
                <li @childActive ><a href='@(item.NodeTypeAlias == "AcademicsItem" ? item.academicsUrl : item.Url)'>@item.Name</a></li>
            }
        </ul>
       } 
        </li>
        }
    </ul>
    }
  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 15, 2014 @ 14:40
    Fuji Kusaka
    0

    Try this instead, remember to at a target=blank if you want an external url

    var extUrl = (item.HasValue("academicsUrl")) ? item.academicsUrl : item.Url;
    var targetUrl = (item.HasValue("academicsUrl")) ? "target=_blank" : "target=_self";
     <a href='@extUrl' @targetUrl >
  • Steve 472 posts 1216 karma points
    Apr 15, 2014 @ 16:47
    Steve
    0

    I've gotten this to work, but if I look at the href url for the externalUrl in the HTML generated, it shows it as the umbraco page, even though it does correctly go to the url that was assigned to it in the property. Whats up with that?

    @{
    var page = Model.AncestorOrSelf(3).Children;
    
    <ul>
    @foreach (var subPage in page) {
          var style = subPage.IsDescendantOrSelf(Model) ? "class=active" : "";
    
    
        <li @style ><a href="@subPage.Url">@subPage.Name</a>
    @if(subPage.Children.Any() && subPage.IsAncestorOrSelf(Model)){ 
        <ul class="academics-items">
            @foreach (var item in subPage.Children.Where("Visible")) {
    var childActive = item.IsAncestorOrSelf(Model) ? "class=active" : "";
                var targetUrl = item.externalUrl ? "target=_blank" : "";
                <li @childActive ><a href='@(item.ExternalLink.externalUrl ? item.url : item.Url)' @targetUrl>@item.Name</a></li>
            }
        </ul>
       } 
        </li>
        }
    </ul>
    }
  • Steve 472 posts 1216 karma points
    Apr 15, 2014 @ 17:26
    Steve
    0

    Sorry for the extra post, but I wanted to expain. "ExternalLink" is a doctype and "url" is a property of that doctype that accepts a text string. So, it should be pulling the text string for the "url" not the item.Url. What do you think is happening? How can I fix it?

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 15, 2014 @ 18:37
    Fuji Kusaka
    0

    Hi Steve,

    I would rather change the property from Url to extUrl. Url is already a helper in razor umbraco.

    So this should work

    var targetUrl = item.extUrl ? "target=_blank" : "";
    var link = item.HasValue("extUrl")? item.extUrl : item.Url;
                <li @childActive ><a href='@link' @targetUrl>@item.Name</a></li>
  • Steve 472 posts 1216 karma points
    Apr 15, 2014 @ 19:37
    Steve
    0

    Unfortunately, that is not the problem. Even with a different property it is showing the full url for the page plus whatever the property holds at the end. So, it has to be something about what is in the variable "item".

  • Steve 472 posts 1216 karma points
    Apr 15, 2014 @ 20:02
    Steve
    0

    Solved. Stupid typo. Apparently if you don't use a valid url when entering it in the text field for the property, umbraco adds the url of the page to the begining of the text string in the property and outputs that. Thanks for all your help Fuji!!

Please Sign in or register to post replies

Write your reply to:

Draft