0

I have a template (views-view-field.tpl.php) and I'm trying to get the raw value of the date field so that i can reformat it and add classes to each seperate part of it (ie day, date, year).

This is what I'm doing:

foreach ($fields as $id => $field)
{ 
if  ($id == 'field_date_published') 
{
echo $field->content //outputs string to page as themed expected ie 23 Oct
echo $field->raw     //simply outputs 3 digits ie 234
}
} 

My question is how can i get the raw value of the time so that i can manipulate day, month and year with specific css classes.

Please do not suggest i solve this problem in any way other than getting the raw data in the template file. I know there are other methods to solve this but i have come to the limit of my understanding in the template file and need to find new avenues of learning to progress.

Thanks in anticpation,

  • did you assign correct name to template file? – monymirza Nov 16 '12 at 5:05
1

This looks like a "feature" in views, for some reason the entity_id is returned in the "raw" property, instead of anything related to the date.
So you will have to work with the "content" property and just make sure you get what you need there - in the view fields settings, set formatter to "plain" and in style settings HTML to none. This way the content will be just the date value from the database.
Check what type of a date field you are using - some of them are stored in the database as the integer timestamp, some as the textual representation of the date. If you want to work with the timestamp, you will have to either change the type of the field, or convert it in the template (probably not very good performance).
For the formatting, you can use the DateObject from the date module, it even has the handy to_array which might be of help :).

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.