Forum
How do I run a function inside a Template filter?
I'm trying to create a filter that returns whether a date is a weekend or not. I can get this working in plain ol' PHP but I suspect I am getting a blank page with the filter because I'm trying to run a function within a class.
I'd be really grateful if anyone can suggest a way around this. It seems a PHP question rather than a Perch question.
class PerchTemplateFilter_weekend_or_weekday extends PerchTemplateFilter
{
public function filterBeforeProcessing($value, $valueIsMarkup = false)
{
function isWeekend($date) {
return (date('N', strtotime($date)) >= 6);
}
if (isWeekend($value)) {
$value = "weekend";
} else {
$value = "weekday";
}
return ($value);
}
}
I solved this by breaking out the function. Here is the solution.