Copied to clipboard

Flag this post as spam?

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


  • Tony Groome 261 posts 804 karma points
    Jan 19, 2015 @ 13:42
    Tony Groome
    0

    Editable Links

    Hi All

    Happy Blue Monday!

    Today's plan is to make editable links. I need the links to be editable by a content editor. Links like at the top of the page Forum Projects Documentation.... I created a new document type with layout of the Master document. Then I tried to use the Related Links type in the document creator. So over in the content editor it gives me 

    Then on Preview this appears

    [ { "caption": "our", "link": "http://our.umbraco.com", "newWindow": false, "edit": false, "isInternal": false, "type": "external", "title": "our" } ]

    instead of my link! What am I doing wrong?

    Thanks.

    Tony

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 13:48
    Jan Skovgaard
    1

    Hi Tony

    Maybe I'm blind but the link from the screendump and the data you're getting seems to be in sync to me?

    /Jan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 13:50
    Jan Skovgaard
    1

    However it seems like there are a couple of issues with the picker reported

    http://issues.umbraco.org/issue/U4-6139 http://issues.umbraco.org/issue/U4-6121 http://issues.umbraco.org/issue/U4-6047

    So perhaps it's not functioning reliably currently so maybe the Multi Url Picker package is the better choice for now? http://our.umbraco.org/projects/backoffice-extensions/multi-url-picker

    Hope this helps.

    /Jan

  • Tony Groome 261 posts 804 karma points
    Jan 19, 2015 @ 14:05
    Tony Groome
    0

    Hi Jan

    I installed the package, but it says to create a new data type and select the multi url picker property editor, does he mean create a new document type? If so the multi url picker doesn't appear. There is some code in his readme.pdf, I don't understand where that is supposed to go. 

    Thanks.

    Tony

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 14:10
    Jan Skovgaard
    1

    Hi Tony

    No you need to create a new datatype based on the multi url picker. You do that in the "Developer section" under "Datatypes", where you right click the "Datatype" folder and choose the "Multi Url Picker" from the dropdown that appears. Then you can setup some configuration on this instance.

    Now you can choose this multi url picker instance in the datatype/property editor drop down on your document type in the settings section.

    Does this make sense? :)

    /Jan

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 14:13
    Jeavon Leopold
    2

    Hi Tony,

    You need a little bit of Razor to render out the links.

    Try this:

    @{
        if (CurrentPage.HasValue("testLink") && CurrentPage.testLink.ToString().Length > 2)
        {
            <ul>
                @foreach (var item in CurrentPage.testLink)
                {
                    var linkUrl = (bool)item.isInternal ? Umbraco.NiceUrl(item.Value<int>("internal")) : item.link;
                    var linkTarget = (bool)item.newWindow ? "_blank" : null;
                    <li><a href="@linkUrl" target="@linkTarget">@item.caption</a></li>
                }
            </ul>
        }
    }    
    

    Taken from the documentation here

    Jeavon

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 14:16
    Jan Skovgaard
    1

    Aaah, I totally misread the initial post. I though that the JSON data was not being updated correct for some reason...you will of course need to render the links as Jeavon says above.

    I must order some stronger glasses...becoming blind it seems :D

    Nevermind me then!

    /Jan

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 14:17
    Jeavon Leopold
    1

    Lol, you managed to get me looking into some of those reported issues with the Related Links editor I wasn't aware of :)

  • Tony Groome 261 posts 804 karma points
    Jan 19, 2015 @ 14:24
    Tony Groome
    0

    Hi Jan

    I created the new datatype and chose the multi url picker in the document type - Woo Hoo! 

    Then I copied @Jeavon's code into the template for this page and it all went south!! 

    I guess I put the code in the wrong place....

    @Jan a friend of ours (an old man he was 78!) had trouble seeing his tv, so instead of getting glasses he got a new tv, it was 56" or 143 cm!!! :)

    Thanks. :)

    Tony

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 14:26
    Jeavon Leopold
    1

    My code is for the Core RelatedLinks editor not MutliUrlPicker, I would go back to using RelatedLinks unless you want to pick media?

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 14:27
    Jeavon Leopold
    3

    If you stick with MultiUrlPikcer then you will need this code:

    @{
      var multiUrlPickerDyn = CurrentPage.testLink;
      if (multiUrlPickerDyn.Any())
      {
        <ul>
          @foreach (var item in multiUrlPickerDyn)
          {
            <li><a href="@item.Url" target="@item.Target">@item.Name</a></li>
          }
        </ul>
      }
    }
    
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 14:30
    Jan Skovgaard
    1

    Hi Tony

    Well I don't think that the code Jeavon posted is usable with the multi url picker.

    You need to use one of these Razor snippets to render links picked using this one, as it's also described on the package page.

    Strongly Typed

    @{
      var multiUrlPicker = Model.Content.GetPropertyValue<MultiUrls>("multiUrlPicker");
      if (multiUrlPicker.Any())
      {
        <ul>
          @foreach (var item in multiUrlPicker)
          {
            <li><a href="@item.Url" target="@item.Target">@item.Name</a></li>
          }
        </ul>
      }
    }
    

    Dynamic

    @{
      var multiUrlPickerDyn = CurrentPage.multiUrlPicker;
      if (multiUrlPickerDyn.Any())
      {
        <ul>
          @foreach (var item in multiUrlPickerDyn)
          {
            <li><a href="@item.Url" target="@item.Target">@item.Name</a></li>
          }
        </ul>
      }
    }
    

    So it's up to you if you want to use the package or just use the related links picker from Umbraco. If so then you should use the snippet from Jeavon.

    @Jeavon: Ok, so it was a tad useful anyway :) @Tony: Haha, Maybe I should just zoom the page by a 1000% in my browser :D

    /Jan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 14:30
    Jan Skovgaard
    1

    Oh...too slow once again. So new glasses and faster fingers I need :D

    /Jan

  • Tony Groome 261 posts 804 karma points
    Jan 19, 2015 @ 14:43
    Tony Groome
    0

    I recreated the datatype to a relatedLinks and put in Jeavon's code. I reloaded the page and it's blank. So thinking I need to call the @umbracoField("findLink") and now I get 

    [ { "caption": "our", "link": "http://our.umbraco.com", "newWindow": false, "edit": false, "isInternal": false, "type": "external", "title": "our" } ]

    Am I close? Maybe I need more than glasses....!!

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 14:48
    Jeavon Leopold
    101

    Ah your property is called "findLink", so the code should be like this:

    @{
        if (CurrentPage.HasValue("findLink") && CurrentPage.findLink.ToString().Length > 2)
        {
            <ul>
                @foreach (var item in CurrentPage.findLink)
                {
                    var linkUrl = (bool)item.isInternal ? Umbraco.NiceUrl(item.Value<int>("internal")) : item.link;
                    var linkTarget = (bool)item.newWindow ? "_blank" : null;
                    <li><a href="@linkUrl" target="@linkTarget">@item.caption</a></li>
                }
            </ul>
        }
    }    
    
  • Tony Groome 261 posts 804 karma points
    Jan 19, 2015 @ 14:55
    Tony Groome
    0

    Jeavon I think I'm going to go to the glasses shop with Jan! If I just read the code instead of just pasting it in.....AGH!

    Thanks a lot! We have hit the jackpot!!

    Now I just have to do this 52 times for my 52 links!! Let the fun begin....or maybe continue!

    Thanks a lot for all your help @Jan & @Jeavon :)

    Tony

  • John C Scott 473 posts 1183 karma points
    Jan 19, 2015 @ 15:49
    John C Scott
    1

    no no don't do it 52 times for 52 links

    question one why do you have 52 links ?

    question two you can make a reusable script which will take the field name as a parameter

    do you want to update the script 52 times if you need to make a change?

    </tuppence-worth>

     

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 15:50
    Jeavon Leopold
    1

    Wow, you have 52 of these editors? I'm guessing you couldn't just add the 52 links into the same RelatedLinks editor?

    I would certainly recommend you create a Razor helper method rather than copying this code 52 times. Do you know how to do that?

  • Tony Groome 261 posts 804 karma points
    Jan 19, 2015 @ 15:59
    Tony Groome
    0

    No I'm not literally going to do it 52 times! What I'm trying to do is set up sections, there will be 9. So each section will be for a department and they will each have their own document type and template. So each department will be able to put in a caption and link for whatever they need. I was hoping to use a foreach to go through each of their sections and display the captions on the webpage. 

    At the moment I have a Master template and there are unordered lists with list items. Here the caption and href links were hardcoded in. We need to change this so each department can change their own links, like here

    <div class="box"><div class="car-section">

                <h4>Facilities</h4>

            </div>

                <ul class="arrows">

               <li>

               <a href="/">Health & Safety</a></li>

               <li>

               <a href="/">Forms</a></li>

       </ul>

            </div>

    This all has to go. So I think I'll put my foreach here looping through CurrentPage.FacilitiesDoc where FacilitiesDoc is the document type. 

    That's the plan at the moment, I'm sure it will change after a while!

    Tony

  • Tony Groome 261 posts 804 karma points
    Jan 19, 2015 @ 16:54
    Tony Groome
    0

    Really confused now!

    On the master template I have

    <div class="box"><div class="car-section">

                <h4>Human Resources</h4>

            </div>

               

    <ul class="arrows">

    <!-- Here -->

                   @foreach(var page in CurrentPage.Children.Where("Visible && DocumentTypeAlias == @0 ", "Hrdoc" ))

    {

     

        if (CurrentPage.HasValue("hrLinks") && CurrentPage.hrLinks.ToString().Length > 2)

        {

            <ul>

                @foreach (var item in CurrentPage.Hrdoc)

                {

                    var linkUrl = (bool)item.isInternal ? Umbraco.NiceUrl(item.Value<int>("internal")) : item.link;

                    var linkTarget = (bool)item.newWindow ? "_blank" : null;

                    <li><a href="@linkUrl" target="@linkTarget">@item.caption</a></li>

                }

            </ul>

        }

        

     

    }

        

     

    <!-- To Here -->

            </ul>

    Under the Heading Human Resources it is blank! I have a document type of alias Hrdoc and a HRDoc template. On the content tab of my HRDoc document type there is a property of type links which is a custom datatype. I ran a test page just like that and it worked. The problem is when I introduced it to the Master Page.

    Anybody any ideas, I'm all out....

    Thanks.

    Tony

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 17:13
    Jeavon Leopold
    2

    I think you need to change CurrentPage to page to use the node in your foreach.

    e.g.

     if (page.HasValue("hrLinks") && page.hrLinks.ToString().Length > 2)    
        {    
            <ul>    
                @foreach (var item in page.Hrdoc)
    
  • Tony Groome 261 posts 804 karma points
    Jan 19, 2015 @ 17:30
    Tony Groome
    0

    Tried that Jeavon, no joy :(

    It must be close though....

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 17:36
    Jeavon Leopold
    1

    Perhaps you are looking for the Children of the Home node, you would need to add AncestorOrSelf(1)?

    @foreach(var page in CurrentPage.AncestorOrSelf(1).Children.Where("Visible && DocumentTypeAlias == @0 ", "Hrdoc" ))
    

    If not, could you post a screenshot of your tree structure and label which doc types are used on which nodes?

  • Tony Groome 261 posts 804 karma points
    Jan 19, 2015 @ 17:59
    Tony Groome
    0

     

     

     

     

     

     

     

     

     

    It didn't like that at all!!

     

     

    I think this is what you mean...

     

     

    The Type:Links is a datatype

    I hope these image make sense! :)

     

     

     

     

     

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 18:03
    Jeavon Leopold
    1

    Ok, and in your content tree on the node that is using the HRDoc template, are you wanting to render the links from child nodes of type HRDoc on this node?

  • Tony Groome 261 posts 804 karma points
    Jan 19, 2015 @ 18:10
    Tony Groome
    0

    This is my Content tree, I'm not sure how to explain what I am trying to do, sorry. The links and captions from the image are what I am trying to get onto the homepage using the master template. I'm not even sure if I should be using the master template or should I be using a separate template? 

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 18:12
    Jeavon Leopold
    1

    Ok, nearly there! What page are you rendering on the front end with the HRDoc template (this one or another)?

  • Tony Groome 261 posts 804 karma points
    Jan 19, 2015 @ 18:13
    Tony Groome
    0

    This one now and other ones as yet uncreated ones later on! 

  • Tony Groome 261 posts 804 karma points
    Jan 19, 2015 @ 18:14
    Tony Groome
    0

    Sorry no I didnt read it right! Just this page with this doc type.

    Other pages with other doc types later on. :)

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 18:19
    Jeavon Leopold
    1

    Ok then, it should be this:

        @if (CurrentPage.HasValue("hrLinks") && CurrentPage.hrLinks.ToString().Length > 2)
        {
            <ul class="arrows">
    
                @foreach (var item in CurrentPage.hrLinks)
                {
                    var linkUrl = (bool)item.isInternal ? Umbraco.NiceUrl(item.Value<int>("internal")) : item.link;
                    var linkTarget = (bool)item.newWindow ? "_blank" : null;
                    <li><a href="@linkUrl" target="@linkTarget">@item.caption</a></li>
                }
            </ul>
        }
    
  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 19, 2015 @ 18:22
    Jeavon Leopold
    1

    p.s. do you have @RenderBody() in your Master template?

  • Tony Groome 261 posts 804 karma points
    Jan 20, 2015 @ 11:07
    Tony Groome
    0

    Hi Jeavon

    Yes I have a @RenderBody() in my master template. Maybe that's why it doesn't like the code? 

    Thanks a lot.

    Tony

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 20, 2015 @ 11:09
    Jeavon Leopold
    1

    Hi Tony,

    No, you need it to be there.

    Do you get an error currently or just that nothing is rendering?

    Jeavon

  • Tony Groome 261 posts 804 karma points
    Jan 20, 2015 @ 11:14
    Tony Groome
    0

    There is nothing rendering. 

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 20, 2015 @ 11:16
    Jeavon Leopold
    1

    Just spotted that your property alias is all lowercase.

    So, try this:

    @if (CurrentPage.HasValue("hrlinks") && CurrentPage.hrlinks.ToString().Length > 2)
    {
        <ul class="arrows">
    
            @foreach (var item in CurrentPage.hrlinks)
            {
                var linkUrl = (bool)item.isInternal ? Umbraco.NiceUrl(item.Value<int>("internal")) : item.link;
                var linkTarget = (bool)item.newWindow ? "_blank" : null;
                <li><a href="@linkUrl" target="@linkTarget">@item.caption</a></li>
            }
        </ul>
    }
    
  • Tony Groome 261 posts 804 karma points
    Jan 20, 2015 @ 11:25
    Tony Groome
    0

    The alias is hrLinks. I think the hrLinks is the grandchild of the Master. Could that be why it's not finding it? The HRDoc is of type Master and the level below, and the doc type is of type HRDoc so is the next level down. Could that be it? 

Please Sign in or register to post replies

Write your reply to:

Draft