0

I've got a content type (Events) and they have event dates. Some of them have multiple dates, some of them haven't. But I want to hide the dates which are in the past.

enter image description here

Obviously, February 15th and April 18th are already passed. How can I hide them?

When I do var_dump($content) in the tpl, all I got is this:

<span class="date-display-single">15 February 2012 - <span class="date-display-start">14:00</span> to <span class="date-display-end">16:30</span></span>

So it looks like I can't filter in PHP since it's already converted into HTML. Any idea how I can filter this?

EDIT: screenshot of my date section
enter image description here

2 Answers 2

2

Presuming you are using the Date module. In the Manage Display settings for the content type, modify the setting for the Date output and put 'now' in the 'starting from' box.

7
  • This would be an awesome solution if not I didn't see that option... See the screenshot in my updated answer!
    – Michiel
    Commented May 24, 2012 at 12:52
  • @Michiel try to update your Date module
    – kalabro
    Commented May 24, 2012 at 12:56
  • Nevermind! I was using an old version of the module!! Thanks a million! EDIT: lol :-) Thanks again!
    – Michiel
    Commented May 24, 2012 at 12:57
  • 1
    No problem, there is usually a proper Drupal solution to these problems :)
    – Lomax
    Commented May 24, 2012 at 13:03
  • @Lomax, I'm not sure if I have to start new question: is it possible to set starting date like "1 day before now"?
    – kalabro
    Commented May 24, 2012 at 13:36
-1

Maybe you could use a regex on it to get the date out? Parse that date with the strtotime() function to compare it to today's date? Then just add a class to the span and hide it with css or get the entire row out of the array.

The regex could look like this:
/(<span class="date-display-single">)([0-9]{1,2}\s[a-zA-Z]*\s[0-9]{4})\s(.*)/

The second group should be your date and you can use the first and third group to reconstruct the line + the extra css class.

5
  • Thanks, but I'm not sure what you mean by "groups"... This is a rather specific solution and will only work in the case where the span with that specific class occurred. I would prefer a more global solution...
    – Michiel
    Commented May 24, 2012 at 12:14
  • 1
    Regex not good idea, because date format can be changed.
    – kalabro
    Commented May 24, 2012 at 12:31
  • 2
    Using regex to parse HTML has bad news written all over it; they are different types of grammar (Chomsky Type 2 v Chomsky Type 3), and are not compatible. You might well get a particular regex to work with some success on a particular HTML snippet, but it's not a robust, scalable solution.
    – Clive
    Commented May 24, 2012 at 12:45
  • Alright, thank you for that information @clive . Can you give me an example of a scalable, robust solution for this case? (other than using the date module)
    – Mike
    Commented May 24, 2012 at 13:56
  • Sure, but it wouldn't work without the date module considering that's the module that implements the date field type in the first place. Lomax's answer is perfectly valid but if you're looking for a code solution there are a few: 1. implement hook_preprocess_node() to override the display variable based on the field properties attached to the $node object. 2. implement hook_node_view() to do the same thing. 3. implement hook_field_prepare_view() to override the field value before it's outputted. That's just off the top of my head, there are probably half a dozen other methods too
    – Clive
    Commented May 24, 2012 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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