Copied to clipboard

Flag this post as spam?

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


  • Clare 37 posts 117 karma points
    Apr 02, 2015 @ 12:00
    Clare
    0

    Razor - how to list nodes with a certain property (where that propertys field is free text)

    I'm trying to create a macro to list descendants where a free text field contains certain text

    The property field for ‘startDateText’ is a Textstring field which could have the following entered:

    • September
    • September 2015
    • 5 September 2015
    • October

    I want to create a list for any that contain ‘September’ in this field.

    This is the what I have at the moment which doesn’t produce a list:

    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @{
        string startToFind = Parameter.ProgrammeStart;
        string levelToFind = Parameter.ProgrammeLevel;
            var root =Model.AncestorOrSelf(1);
        var programmeNames = root.DescendantsOrSelf("Programme").OrderBy("programmeName").ToList();
    
    <div>
        <ul class="programme-list">
            @foreach(var item in programmeNames)
            {
        string[] startDateText = item.startDateText.ToString().Split(',');
        if ((item.level == levelToFind) && (startDateText.Contains(startToFind)))
                {
                <li>
            <a href="@item.Url">@item.programmeName - @item.qualificationType</a> 
            </li>
            }
            }
        </ul>
    </div>
    
    }
  • Daniel Larsen 116 posts 381 karma points
    Apr 03, 2015 @ 10:10
    Daniel Larsen
    0

    Hi.

    I was just wondering why you haven't used a DateTime field? Are you not making it harder for yourself? :-)

    Happy easter!

    Daniel

  • Clare 37 posts 117 karma points
    Apr 07, 2015 @ 10:38
    Clare
    0

    Hi Daniel,

    The editor needs to be able to enter dates as specific (5 September 2015) but also as just the month and year if the exact date not yet known (September 2015) so that is why we've kept it as free text rather than the DateTime field

    cheers,

    Clare

  • Daniel Larsen 116 posts 381 karma points
    Apr 08, 2015 @ 14:14
    Daniel Larsen
    0

    Hi Clare

    Then why not use a checkbox that when checked, only takes the month and year of the choosen date from a datepicker? :-)

    Daniel

Please Sign in or register to post replies

Write your reply to:

Draft