Using the id number is a poor way to do this. The content link is "/about-us/events".
How can I make easy reference to the content, primarily as a link to the content, without mentioning the id please?
In several other places I've explored the Umbraco content, got the Alias, taken a number of different approaches... but I still think I'm missing a simple, direct, approach.
Like you've said, Document Types can be used to find content. That's typically how I do it, as ids are likely to change when publishing to different environments.
Another way to do it would be to store content ids in the node you're currently residing in. E.g. using content pickers etc.
I've used both approaches described, and both make sense.
Yes, searching by DocumentTypeAlias, and the first of these, aligns with the way Umbraco works.
Another way to do it would be to store content ids in the node you're
currently residing in. E.g. using content pickers etc.
I wanted to avoid this, as it is just a single link that I'm putting in a partial.
I suppose, if I'm looking for a quick fix then there is no difference between using the id and hard-coding "/about-us/events", so I might as well use the more descriptive (hard-coded) version.
I'm not quite sure what you mean by App Settings (in Umbraco terms)? If I had a Document Type I could add a property to it, which is what I thought Alex meant, but I'm in a free-standing Partial View.
Sorry I meant adding a content picker to a node. But this is typically more useful for navbars or something.
I'd search on document type (which is what I always do) since like Paul said, the url may change. If you accidentally change the name of the node, it'll change the url too.
Quickly convert id to a content reference
Hello, apologies that this is a simple question but it has been bugging me. As an example, I have this:
Using the id number is a poor way to do this. The content link is "/about-us/events".
How can I make easy reference to the content, primarily as a link to the content, without mentioning the id please?
In several other places I've explored the Umbraco content, got the Alias, taken a number of different approaches... but I still think I'm missing a simple, direct, approach.
What about finding the item by document type alias?
Maybe something like this:
Like you've said, Document Types can be used to find content. That's typically how I do it, as ids are likely to change when publishing to different environments.
Another way to do it would be to store content ids in the node you're currently residing in. E.g. using content pickers etc.
Thank you both.
I've used both approaches described, and both make sense.
Yes, searching by DocumentTypeAlias, and the first of these, aligns with the way Umbraco works.
I wanted to avoid this, as it is just a single link that I'm putting in a partial.
I suppose, if I'm looking for a quick fix then there is no difference between using the id and hard-coding "/about-us/events", so I might as well use the more descriptive (hard-coded) version.
Thank you.
If it was me I would not use the hard coded path.
The url is far more likely to change than the id.
If you don't want to get it by doc type then do what Alex says and store it in the App Settings.
I'm not quite sure what you mean by App Settings (in Umbraco terms)? If I had a Document Type I could add a property to it, which is what I thought Alex meant, but I'm in a free-standing Partial View.
Do you mean in a config file?
Sorry I meant adding a content picker to a node. But this is typically more useful for navbars or something.
I'd search on document type (which is what I always do) since like Paul said, the url may change. If you accidentally change the name of the node, it'll change the url too.
Thank you both.
What I always use in this type of cases is creating an extensions class which adds extension methods to the UmbracoHelper.
Then using the
TypedContentSingleAtXPath
method I take the correct content node:Above examples takes the first node of alias
contact
under the roothome
node.Hope this helps!
/Michaël
is working on a reply...