Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • William Corry 34 posts 171 karma points
    Oct 24, 2014 @ 14:16
    William Corry
    0

    Using the calendar in a special offers page

    I am not sure if this is possible but what I am trying to do is create a special offers page.

    So you have your parent page which displays all the children pages with a brief summary of each page etc. What I want to do is add a time limit on these pages so for example and offer runs from x date to y date the offer with its summary will display.

    I have the children pages with the calendar and I have a foreach loop which is working however the content of those pages is always showing on the parent page as I am not sure how to display the title, content fields under the calendar loop. eg:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Archetype.Models;
    @using Archetype.Extensions;
    @using Newtonsoft.Json
    @using Umbraco.Web;
    @using UrlPicker.Umbraco.Extensions;
    @inherits UmbracoTemplatePage
    @using KS.Umbraco7.Calendar.Core
    
    @{
        Layout = null;
        var archetype = CurrentPage;
    }
                @{
                    var cnt = 0;
                    var active = "class=active";
                }
                    @{
                        active = "active";
                        cnt = 0;
                    }
    @foreach(var featured in archetype.Children){
    if(featured.makeFeatured){
    foreach (CalendarEvent ce in Calendar.getEvents(DateTime.Now, DateTime.Now.AddDays(1), "featuredOffer").Take(1)){
    var img = featured.GetPropertyValue("image");
    var count = featured.Count();
    @if(cnt == 0){
    @ce.content.featuredTitle } else {
    @featured.featuredTitle
    }
    @Html.Raw(featured.featuredText)
    @{
    int b = 0;
    var action = featured.GetPropertyValue("featuredCallToAction");
    foreach (var call in action) {
     var link = call.GetValue("urlPicker");
    if(link != null && !string.IsNullOrWhiteSpace(link.Name)) {
    @call.GetValue("actionTitle")
    }
    b++;
    }
    }
    @foreach (var banner in img)
    {
    image = Umbraco.TypedMedia(banner.GetValue("image"));
     var title = Html.Raw(featured.Title);
    IMAGE
                            if (cnt == 0) { active = ""; }
                            cnt++;
                            }
                        }
                    }
    
    

    Obvioulsy at the moment this is pull all the data from the parent loop. Hopefully what I have described makes sense.

     

    I am thinking I need an if statement but not sure what call I need any help would be appriciated thanks

  • Ole Martin Bakke 112 posts 624 karma points
    Oct 25, 2014 @ 14:21
    Ole Martin Bakke
    0

    I'm not sure if I understand all the things you are trying to do. But as I understand it you have a parent page where you want to list child pages with a currently active offers. Much like a list of events happening today.

    For me it looks like your foreach-loop will loop all children marked with the makeFeatured boolean and for each of this you list the first node matching the datetimes, and that the event will be the same every time.

    I guess you structure is like this:

    -Parent
    --Child (with property featuredOffer that is the calendar datatype and the boolean makeFeatured)
    --Child
    --Child

    Then I would list current offers like this.

    @foreach(CalendarEvent ce in Calendar.getEvents(DateTime.Now, DateTime.Now.AddDays(1), "featuredOffer", CurrentPage.Id)){
    if(ce.content.GetPropertyValue("makeFeatured")){
    <h1>@ce.content.GetPropertyValue("featuredTitle ")</h1>
    }
    }

    This will hopefully only list the child elements matching the datetime and marked as makeFeatured.

    You can access all the properties on you chile-nodes via ce.content.GetProperyValue()

    As I said, I'm not sure if I understand what you are trying to do, so sorry if this is a total miss.

  • William Corry 34 posts 171 karma points
    Oct 27, 2014 @ 14:05
    William Corry
    0

    Thats great works like a charm although:

    if(ce.content.GetPropertyValue("makeFeatured")){

    needed to be:

    if(ce.content.GetPropertyValue("makeFeatured")){

    to work for me

  • Ole Martin Bakke 112 posts 624 karma points
    Oct 27, 2014 @ 20:08
    Ole Martin Bakke
    0

    Thats great!

Please Sign in or register to post replies

Write your reply to:

Draft