I've just tried to include a related links field within one of my pages. The menu and interface of inserting the links and adding a caption all seem to work correctly however, when it comes to the output on the actual site I'm seeing what looks like JSON (See below). Is this the way in which this datatype is supposed to be presented in Umbraco 7? If so, how is this then converted into useable anchor links within a site?
Thanks for the reply. As I mentioned earlier I am new to MVC so could you briefly summise in which cases each would be preferred as I am unsure at this point in time as to the difference between typed and dynamic.
My code block is to be stored in the MasterLayout for my site which contains the header and footer. The related links are to be displayed in the footer of each page and are defined as properties of the home content page which is the root content page of my site.
I managed to find the following code elsewhere but are the methods you have enclosed above more scalable (e.g. will this fail if there are no related links in the home content page or will it just not render anything.
Also, at the moment I am using this code inline within my master template. Is it acceptible to do this or should this code be stored in a partial view and rendered to the page using @{ Html.RenderPartial("RelatedLinks");} for example?
The code snippets in the documentation are well tested and have already been tweaked and improved a few times, I would recommend using them.
I do have a package which I think makes working with some of the core property editors including related links much easier in terms of Razor, epecially for starters. You can find it here If you install you will need to adjust and Razor you have for the editors it converts. This is the Razor snippet you can use if you install it
With regard to Typed vs Dynamic models, it is really a personal preference. Fundamentally Typed gives you code Intellisense in Visual Studio or WebMatrix but Dynamic is more concise so if you are only using the web based template editor only it is generally preferred.
This solution does not seem to persist across pages. For some reason, the related links are only display on the homepage. This sort of makes sense as this is where the related links are defined but how can I ensure that the related links are accessible to all children of the homepage (as the call to the related links partial view is made in my master template)?
Which code did you use in the end? Could you post it and then I can help you make it recursive so that it will look up the tree form where is being executed to find the first node that has the "relatedLinks" property and render that out.
No problem, to make this recursive so that it will look up the tree (to the homepage) from where it is rendering until it finds a node with the "relatedLinks" property, all you need to do is add three "true" parameters, so it would be like this:
Great. Thanks. This worked a treat!
One more question. If I wanted to count the number of links I am outputting and append the count to the end of the link, would I be able to do the following:
var linkCount = 0;
@foreach (var item in Model.Content.GetPropertyValue<JArray>("relatedLinks", true)){
var linkUrl = (item.Value<bool>("isInternal")) ? Umbraco.NiceUrl(item.Value<int>("internal")) : item.Value<string>("link");
var linkTarget = item.Value<bool>("newWindow") ? "_blank" : null;
<li><a href="@linkUrl" target="@linkTarget">@(item.Value<string>("caption")) Link@imageCount</a></li>
@imageCount ++;
}
Or are variables such as this handled in a different way in Umbraco? (Apologies if this is a stupid question, I'm a Javascript developer by trade so not too sure on how this is handled in C# / Umbraco.
I dont know whether is this the right place to ask this question. I need to assign the related link property values to my Back Office using Surface Controller. Any body knows the proper way to do it?.
I have to do it as the after effect of some user submitted Data. When user submits data, a content page is automatically generated using the surface Controller. And I have done that. Now I need to set the media files into a related link propery value of the generated file.
Problems with related links in Umbraco 7.1.1
Hi all,
I've just tried to include a related links field within one of my pages. The menu and interface of inserting the links and adding a caption all seem to work correctly however, when it comes to the output on the actual site I'm seeing what looks like JSON (See below). Is this the way in which this datatype is supposed to be presented in Umbraco 7? If so, how is this then converted into useable anchor links within a site?
Thanks in advance.
Hi Jason,
Please find sample Razor code for both Typed and Dynamic models here
Jeavon
Hi Jeavon,
Thanks for the reply. As I mentioned earlier I am new to MVC so could you briefly summise in which cases each would be preferred as I am unsure at this point in time as to the difference between typed and dynamic.
My code block is to be stored in the MasterLayout for my site which contains the header and footer. The related links are to be displayed in the footer of each page and are defined as properties of the home content page which is the root content page of my site.
I managed to find the following code elsewhere but are the methods you have enclosed above more scalable (e.g. will this fail if there are no related links in the home content page or will it just not render anything.
Also, at the moment I am using this code inline within my master template. Is it acceptible to do this or should this code be stored in a partial view and rendered to the page using @{ Html.RenderPartial("RelatedLinks");} for example?
Hi Jason,
The code snippets in the documentation are well tested and have already been tweaked and improved a few times, I would recommend using them.
I do have a package which I think makes working with some of the core property editors including related links much easier in terms of Razor, epecially for starters. You can find it here If you install you will need to adjust and Razor you have for the editors it converts. This is the Razor snippet you can use if you install it
With regard to Typed vs Dynamic models, it is really a personal preference. Fundamentally Typed gives you code Intellisense in Visual Studio or WebMatrix but Dynamic is more concise so if you are only using the web based template editor only it is generally preferred.
Any further questions let me know.
Jeavon
Hi Jeavon,
This solution does not seem to persist across pages. For some reason, the related links are only display on the homepage. This sort of makes sense as this is where the related links are defined but how can I ensure that the related links are accessible to all children of the homepage (as the call to the related links partial view is made in my master template)?
Cheers Jason
Hi Jason,
Which code did you use in the end? Could you post it and then I can help you make it recursive so that it will look up the tree form where is being executed to find the first node that has the "relatedLinks" property and render that out.
Jeavon
Hi Jeavon,
I used the following code:
This is stored within a partial view and is called in my master template using:
Thanks for all of your help so far.
No problem, to make this recursive so that it will look up the tree (to the homepage) from where it is rendering until it finds a node with the "relatedLinks" property, all you need to do is add three "true" parameters, so it would be like this:
Great. Thanks. This worked a treat! One more question. If I wanted to count the number of links I am outputting and append the count to the end of the link, would I be able to do the following:
Or are variables such as this handled in a different way in Umbraco? (Apologies if this is a stupid question, I'm a Javascript developer by trade so not too sure on how this is handled in C# / Umbraco.
Awesome!
Pretty close:
Great. Thanks. I was pretty close! Once I start getting used to the Razor syntax I should be okay. Thanks for all of your help!
Awesome! This bit
@("Link" + imageCount)
is a little annoying, if there was a space it could just beLink @imageCount
Yeah but that's concatenation for you!
Hi Guys,
I dont know whether is this the right place to ask this question. I need to assign the related link property values to my Back Office using Surface Controller. Any body knows the proper way to do it?.
I have to do it as the after effect of some user submitted Data. When user submits data, a content page is automatically generated using the surface Controller. And I have done that. Now I need to set the media files into a related link propery value of the generated file.
Any help would be appreciated.
is working on a reply...