6

I have a component with a field "video" which is linked to a component which consist of a youtube url. I just want to fetch that url from that component. My code below what I tried

@if(Model.Component.Fields["video"].Containskey("video"))
{
@Model.component.Fields["video"].LinkedComponentValues[0].Fields["code"].Value
}

I am getting "The given key was not present in the dictionary"

Normally, if I use this code I can fetch that youtube Url @Component.Fields.video.Fields.code But when using dd4t template I am facing issues.

1 Answer 1

4

My guess is that the linklevel for your component template is set to 1; this means that DD4T will provide you with the linked component id's but not its content. If you increase the linklevel you should be able to access the field data.

Linklevels is a parameter setting on the publishing template; it determines how "deep" the structure is that you will have available on the content delivery side. It defaults to 1, and with every increase one additional level of componentlinks is resolved and included.

Alternatively, you could also publish that video component dynamically and retrieve it on the fly, but that is more complicated.

2
  • I tried with setting linklevel 4.Its working for me.Thanks
    – roop
    Commented Jul 1, 2013 at 14:38
  • Do make sure to monitor your performance once you increase this - there's a reason why it defaults to 1, and the size of your data objects can increase considerably.
    – Nuno Linhares
    Commented Dec 18, 2015 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.