[Templates] Stringifying objects in templates
[prev]
[thread]
[next]
[Date index for 2004/10/25]
I ran into an interesting issue last night trying to get an unusual
situation to work. I have a Class::DBI object which has a has_many
relationship for objects representing dates. Like so:
# perl code
package Class;
...
Class->has_many(class_dates' => Schedule, 'class_id');
package Schedule;
Schedule->columns(Essential=>qw(class_date...));
Schedule->has_a(class_date => Class::Date);
In the template I wanted to take the stringified class_date object
("2004-10-25 09:00:00") and split on the white space to get the
individual day and hour components. My first thought was:
[day, time] = schedule.class_date.split(' ');
But this tried calling the split() method on the Class::Date object
rather than the stringified version. So then I tried:
[day, time] = ${date.class_date}.split(' ');
Which just gave me a syntax error. I've since switched to a better
method which avoids this issue. But I'm curious how I would go about
this? The trick seems to be forcing TT to use the variable as a string
rather than an object.
Drew
--
----------------------------------------------------------------
Drew Taylor * Web development & consulting
Email: drew@xxxxxxxxxx.xxx * Site implementation & hosting
Web : www.drewtaylor.com * perl/mod_perl/DBI/mysql/postgres
----------------------------------------------------------------
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
[Templates] Stringifying objects in templates
Drew Taylor 14:26 on 25 Oct 2004
|