display a field only the first time a view is shown

Topics: Customizing Orchard, Writing modules
Apr 20, 2012 at 7:29 PM

Hi:

I'm currently writing a content part to be added to the user tyupe and to hence be used in the profile module.

I'm asking the user for there date of birth. Naturally I only want to show this field the first time they edit there profile. What is the best/easiest way of doing this.

Regards

Sean.

Developer
Apr 21, 2012 at 5:58 PM

I can think of the following ways:

  • Override the field's shape (specific only for that content type, either by naming the shape appropriately or changing the shape in a Placement.info with the Shape parameter) and check if the date is set there.
  • Use a custom part for this and check the existence of the date in the driver.
Apr 21, 2012 at 6:15 PM

I am using a custom part already—should have made that clear!

If I was to check the date, would checking against datetime.minvalue do the job?

And I’m assuming setting the css display to “none” would do the trick.

Cheers

Sean.

From: Piedone [email removed]
Sent: 21 April 2012 18:58
To: Sean Farrow
Subject: Re: display a field only the first time a view is shown [orchard:353011]

From: Piedone

I can think of the following ways:

  • Override the field's shape (specific only for that content type, either by naming the shape appropriately or changing the shape in a Placement.info with the Shape parameter) and check if the date is set there.
  • Use a custom part for this and check the existence of the date in the driver.
Developer
Apr 21, 2012 at 6:31 PM

If your datetime column could be null than the property in the result object will be null as well, otherwise I don't know for sure, could be MinValue... I would hide the field completely from the view, its more robust this way, although in this case hiding with css wouldn't harm either.

Apr 21, 2012 at 6:42 PM

How would one hide this—a boolean in the model?

Cheers

Sean.

From: Piedone [email removed]
Sent: 21 April 2012 19:32
To: Sean Farrow
Subject: Re: display a field only the first time a view is shown [orchard:353011]

From: Piedone

If your datetime column could be null than the property in the result object will be null as well, otherwise I don't know for sure, could be MinValue... I would hide the field completely from the view, its more robust this way, although in this case hiding with css wouldn't harm either.

Developer
Apr 23, 2012 at 9:47 AM

I'd simply use an if in the view for checking if the date is set. Now I don't know whether you're talking about a field in the Orchard sense or the date is just a property on your part. If the former, you should override the field's rendering shape to do this, if the latter you could do this in your part's shape template.