As you can see about a third of the way in I call on
@result.DocumentTypeAlias
is there-a way to get the pretty name for this, ie instead of 'newsStory' its 'News Story', I did consider a large case statement that just grabbed the Alias, turns it into a pretty var, and chucks it out, but then id have to update this everytime a new category is added.
I don't believe that there is a nice way to achieve what you are after if I'm honest. At least not in a best practice approach. The only way I know of would be to start using things like the Content Service, which you don't really want to be doing in your front end code as it hits the Database every time.
Using a dictionary is a good way to do it, but it does mean you need to keep your dictionary up to date when you add document type, or change their names (this latter bit you probably won't be doing very often).
The Dictionary functionality does exist out of the box, kind of. The reason you are getting no results back is that you have to build your dictionary so it knows what to look up. This can be done in the back office of Umbraco under the "Settings" section. You should see a tree entry called "Dictionary", this would be where you'd construct your entries.
The value you are passing into the method GetDictionaryValue is the key/name that it will use to look up the value to display.
Result, thank you both, maintaining the dictionary is easier than maintaining code. I can use this functionality in place of where I often think a switch case thingy would be best.
I suspect that the over-arching objective is to show the "Type" of page, not the name of the individual page as he is after the name of the page Type not the name of the page itself, which is what your code would provide :-)
Get a pretty Document Type Alias to show in search results
Hey guys, here is my results snippet:
As you can see about a third of the way in I call on
is there-a way to get the pretty name for this, ie instead of 'newsStory' its 'News Story', I did consider a large case statement that just grabbed the Alias, turns it into a pretty var, and chucks it out, but then id have to update this everytime a new category is added.
Hi Kieron,
Maybe its possible but I have not seen it accessible in the IPublishedContent object.
But what about you would use Dictionary for it ?
You could then have better control of what will be outputted.
If the site would need later translations it would work out of the box.
Hey, thanks for your help.
Is that a drop-in piece of code? I've never used the dictionary before, but dropping that in just brings back nothing, no errors though :D
Hi Kieron,
I don't believe that there is a nice way to achieve what you are after if I'm honest. At least not in a best practice approach. The only way I know of would be to start using things like the Content Service, which you don't really want to be doing in your front end code as it hits the Database every time.
Using a dictionary is a good way to do it, but it does mean you need to keep your dictionary up to date when you add document type, or change their names (this latter bit you probably won't be doing very often).
The Dictionary functionality does exist out of the box, kind of. The reason you are getting no results back is that you have to build your dictionary so it knows what to look up. This can be done in the back office of Umbraco under the "Settings" section. You should see a tree entry called "Dictionary", this would be where you'd construct your entries.
The value you are passing into the method
GetDictionaryValue
is the key/name that it will use to look up the value to display.Does that help?
Nik
Hi I will give it a go tomorrow thank you for the explanation!
Result, thank you both, maintaining the dictionary is easier than maintaining code. I can use this functionality in place of where I often think a switch case thingy would be best.
Why not just show :
Or am I missing hte point?
I suspect that the over-arching objective is to show the "Type" of page, not the name of the individual page as he is after the name of the page Type not the name of the page itself, which is what your code would provide :-)
Yeah as Nik says, basically :-)
Oh, my mistake. Apologies.
is working on a reply...