Yes you can put this straight into a template as they are Razor. There is a question of coding style how much logic you put in your templates. I think this is probably fine
On each page you have Umbraco context.
Content picker stores id to the destination page.
So you have to get this id and get url to this page from Umbraco context.
You can do that like that :
var nodeId = Umbraco.AssignedContentItem.GetPropertyValue<int>("Link1");
var node = Umbraco.TypedContent(nodeId);
var url = node.Url;
New to v7 and Razor - Simple NiceUrl link
Hi all, Im just moving over to v7 and MVC from v6 and its all a bit of a learning curve again. Just trying to add a simple link into a template.
In v6 I would use:
Now it seems so difficult to either find documentation on simple things like this using Razor or its just more complicated to implement.
I've tried:
but i get a runtime error
How do i add a simple NiceUrl link that works similar to v6?
Thanks
Is the field part of the current document?
Just use
or
If you need the full URL
and I can write that straight into the template?
I was thinking that it might have been simplified in V7 from V6 not more complex :-/
Sorry - I posted my reply in the wrong place - then deleted it! Roger is referring to my response below.
Hi, thanks for the reply, No it isnt part of the current page.
Its a link in a template that is selected using a content picker and needs to be recursive with it being in the master template
In V6 i would use:
Just to give you a visual, its the advert link here...
Ahh..
OK - if you want a one liner... though I don't think it's as readable.
Yes you can put this straight into a template as they are Razor. There is a question of coding style how much logic you put in your templates. I think this is probably fine
Hi Roger,
On each page you have Umbraco context. Content picker stores id to the destination page. So you have to get this id and get url to this page from Umbraco context.
You can do that like that :
Thanks, Alex
https://ua.linkedin.com/pub/alexander-skripnik/66/60b/352
Hi Alex,
Interesting use of AssignedContentItem - can you explain why you use that over CurrentPage / Model.Content ?
I think you'd also need to add the recursive boolean to your GetPropertyValue call for that to work as Roger needs?
Thanks so much guys,
Steve, i used your inline method with the recursive boolean and it works great!
Its all new to me so a big learning curve on the way I think!
Thanks again!
I'd recommend using Visual Studio for Razor.. the intelisense is a life saver!
These are also helpful (says v6 but good for v7 too).
https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets
Yeah i do use VS as a rule. Im just new to Razor, only just moving to umbraco V7+ so i think its a learning curve for me!
Thanks
is working on a reply...