How can I detect the state of Content at View startup?

谁说我不能喝 提交于 2019-12-11 16:45:44

问题


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

  1. give the demo item a unique value in one of the fields and check for that in the template
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!