In ICmsView, MyView provides a few things like:
MyView.Name: FCTRL - Dark Card w Tawk JS API Experiments
MyView.Path: /Portals/0/2sxc/Content/FCTRL
What is weird is that I need the template filename. And according to the View Configuration it should be .Path.
What is really interesting is that if you look at the Data in the Angular UI when editing the View, you see:
Which is EXACTLY what I need. But on the backend, (as you can see above) MyView.Path instead outputs the path to the View's folder root. But the correct way to get that nowadays is MyView.Folder.Url
and I think I saw somewhere that .Path is deprecated now.
Given that the data IS THERE for the actual entity, but not visible when accessing it through the CmsView interface, is there some way to get the filename (path+filename would be fine)? Hopefully something easy or simple, even if not obvious?
I also tried AsEntity(MyView).Get("Path")
and a few other variations thinking that the View Configuration is just another entity, but from the errors, it looks like MyView is not allowed to be (ICanBeEntity or something) an entity.
The data is clearly right there, how can I access it from my C# Razor code?
I found a solution, but it doesn't seem like a good solution. Hopefully the magicians at 2sxc will provide a better answer someday and/or make the right answer more discoverable. I like the Metadata suggestion above, but I could not get what I needed that way (in 2sxc v18.6+ or v19).
From what I said above, it was obvious that if I could get the View Settings as an Entity, that I could just .Get() what I needed.
Here is how I did it:
var myView = AsItem(App.Data.GetStream(name: "2SexyContent-Template")
.Where(t => t.EntityId == MyView.Id)
.FirstOrDefault()
);
So, we are just using the .Id of MyView and the (somewhat hidden) name of the Content Type used for View Settings. Now I have myView as an Entity whereas MyView is an ICmsView. Then the value is available as dynamic or typed to a string:
<pre>
myView.Get("Path"): @myView.Get("Path")
myView.String("Path"): @myView.String("Path")
</pre>