问题
Lets assume I have created my own custom view for a Link content type. When the user adds a 2sxc Content app to a Pane, then picks the Content Type (Link) then my custom View, when it first starts up, how can I detect that a) the View does not use a Demo item vs. b) the View uses a demo item and is showing the Demo item vs. c) its not the first time and there is a real user added Content (Entity) in place?
I have done stuff like this for the a) case:
var link = AsDynamic(Data["Default"]).First();
then checked if it was null, but it looks like my View code never executes and instead I just see, "No demo item exists for the selected template."
If I do assign a demo, is there a more elegant way to know that the Entity I am handed as Content.First() or Data["Default"]).First() is a Demo item and now a user created Entity? Currently I am hard-coding the EntityId in the template and testing for that.
回答1:
The template system does not render the template if there is no demo item (unless it's a template without a content-type). When we need this, we have two ways
- give the demo item a unique value in one of the fields and check for that in the template
- check the demo-item ID on GUID and check for that
(Content.EntityGuid == ...)
回答2:
IsDemoItem property added in 2sxc 10.06
Dynamic Entity
来源:https://stackoverflow.com/questions/56720774/how-can-i-detect-the-state-of-content-at-view-startup