tags:

views:

270

answers:

2

Is it in usercontrols / xslt renderings possible to check wheter an item has it's publishing restricted or is not publishable in the Sitecore CMS? We get some situations where we explain users of the CMS how to set publishing restrictions and get back questions about items showing standard values on the website. For example:

  • I have an item and it contains fields with information.
  • I publish this item and everthing is fine. Content is being shown on the website.
  • I change publishing restrictions and say it can only be published from 23-02-2010 to 25-02-2010.
  • What happens now is that when i publish the website again, the item that was shown correctly before now shows Standard Values.

EDIT:

  • The item i am talking about has only one version. (Dutch - version 1) The item is just made through insert from template and filled with information. After it is filled with the info, Publishing restrictions are set up. When this is done and the item is not falling within the date of that restriction i see standard values @ front.

Publishing restrictions can be used to make sure information is only shown in some period of time right? Is this something we can fix in our code? Can we check wheter an item is not in the range of the public resctrictions / unpublished?

A: 

Here is the possible explanation of the behavior you described. You have several versions of your item, and when you put publish restrictions to the version you're working with (typically, the latest one), it gets unpublished. If one of the previous versions, which becomes publishable now, doesn't override standard values, you'll see these standard values on the front-end.

The fix for this depends on your needs. For instance, if you wish to manage entire item, set the publish restrictions on an item level.

As for you initial question, any field of an item can be addressed from user control / XSL rendering (for instance, sc:fld function). But keep in mind that you are querying web database from rendering. If the publish restrictions are set, and the item is not publishable, you won't get this item and its fields from the rendering / sublayout.

Hope this helps.

Yan Sklyarenko
I edited my question to be even more clear! Thx for answering but recheck my question plz
Younes
As for the last part of your answer: I understand that when an item is unpublished I won't be able to render values from that particular item. How can i make sure that my code won't try to. Is there any way to check in the code if in item is publishable / falls within publish restriction date? That way i can prevent items to go default value mode when i unpublish / restrict.
Younes
I see every item has an option to check where it's Empty. When i'm using this option í'm able to hide the standard values when the item doesn't have a version!
Younes
>> I see every item has an option to check where it's EmptyWhat option are you talking about here? Where did you find it? Seems I lost the point here...
Yan Sklyarenko
A: 

So again to give other users the option to check for an answer to this question i'll answer my own question.

If a user in the CMS of Sitecore specifies a range where an item can be published in and you see a standard value appearing on the front:

  • Look up the class / rendering whatever that shows the information
  • Make sure your code is checking for versions available

If there is only one version available like in my case , and there are no other versions while the date of today falls outside the range specified doing a simple Item.Empty check will be enough.

Whenever you have a Sitecore item that you need to handle:

item has versions in context language?? -> item.Versions.Count

item may be published?? -> !item.Publishing.IsValid(DateTime.Today, false)

item has layout?? -> item.Visualization.GetLayout(Sitecore.Context.Device)

I hope this information will once be usefull to somebody!

Younes