3

So I have a Rendering, it takes a data source, but there is a requirement to schedule a specific data source item to show up for that rendering between a given time frame. Is that possible within Sitecore? I know you could use the personalization rules engine to achieve something similar, but it's not as intuitive as I would like. Is there any other options?

  • 1
    Your final renderings are not shared, so it should be possible to use those and create another version with the specific datasource. You can schedule that version to show for a given time frame. Never tried this, but I think it should work. – Gatogordo Dec 2 '16 at 13:45
  • I used Gatogordo idea few years ago, we had automatic publishing and we didn't have any issues. – Vlad Iobagiu Dec 2 '16 at 14:11
2

You can use item versions and publishing restrictions. With publishing restrictions you can set a time frame(start and end) for when and item version is active

  • If it is sitecore 7.2 or less it will not work as the presentation details are shared across all versions – Hishaam Namooya Dec 7 '16 at 17:56
2

Unlike the renderings, your final renderings (available in 8+) are not shared, so it should be possible to use those and create another version with the specific datasource (the guid of the datasource is part of your rendering field value).

You can schedule that version to show for a given time frame. Don't forget that you need the publishing agent if you want it all to happen automatically ;)

0

While @Diego answer works, publish restrictions doesn't perform automatic publish when the date comes. Content authors need to perform the publish (unless you have automatic publish setup) action before the scheduled date.

By default we have few Date conditions.

enter image description here

but if you would like to change the datasource between specific timeframes you can use some custom rule as below

I used something similar to below previously for overcoming the problem

    public class NowBetweenCondition<T> : WhenCondition<T> where T : RuleContext
      {
        /// <summary>
        /// Gets or sets the UTC start date.
        /// 
        /// </summary>
        /// 
        /// <value>
        /// The UTC start date.
        /// </value>
        public string StartDate{ get; set; }

        /// <summary>
        /// Gets or sets the UTC end date.
        /// 
        /// </summary>
        /// 
        /// <value>
        /// The UTC end date.
        /// </value>
        public string EndDate{ get; set; }

        /// <summary>
        /// Executes the specified rule context.
        /// </summary>
        /// <param name="ruleContext">The rule context.</param>
        /// <returns>
        /// <c>True</c>, if the condition succeeds, otherwise <c>false</c>.
        /// </returns>
        protected override bool Execute(T ruleContext)
        {
          DateTime utcNow = DateTimeProvider.GetUtcNow();
          DateTime dateTimeStart = DateUtil.ParseDateTime(this.StartDate, DateTime.MaxValue);
          DateTime dateTimeEnd = DateUtil.ParseDateTime(this.EndDate, DateTime.MaxValue);
          if (dateTimeStart.Kind != DateTimeKind.Utc || dateTimeEnd.Kind != DateTimeKind.Utc)
            Log.Warn("<yournamespace>.NowBetweenCondition<T> expects UTC date, but date with different kind has been assigned to StartDate: " + this.StartDate + "or EndDate: "+ this.EndDate, (object) this);
          return utcNow > dateTimeStart && utcNow < dateTimeEnd;
        }
      }

Validate the inputs properly to avoid surprises.

Create a new rule in master db under system/settings/rules/definitions/elements

enter image description here

  • I kind of knew that you could use the personalization rules engine to achieve this although personalization seems like it may not be the best place for this. There is a client that I work with that have used the Day of the month condition to display a different piece of content on each day of the month, but something about that seems wrong. I like this idea of extending the rules end except like I said personalization seems like the wrong place to schedule items. – Dylan Young Dec 3 '16 at 1:40
  • @DylanYoung "I know you could use the personalization rules engine to achieve something similar, but it's not as intuitive as I would like" - what is the intuitiveness you are looking for? On the other hand your rendering can be intelligent enough to pull the right data source from specific folder as per date or period and fallback to default if none is available. But this requires content authors to understand the rendering better which is a normal case with component user guide. I would like to know the perspective behind "personalization seems like wrong place". – phani Dec 3 '16 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.