Please note that the forum isn't realy used anymore.

If you have questions, want support or just simply want to talk to us you can find us on slack.

 

Calling 40 times a template modifier

Hi,

I have a module action/template that has approx 40 dates (and its times) to show, so I do the following in my template.

{$dates.start_date|date:'D d/m/Y':{$LANGUAGE}} <small><strong> $dates.start_date|date:'H:i':{$LANGUAGE}}</strong></small>

This line makes the page load for about 3.5 to 4 seconds. As I previously mentioned, for 40 dates, the 'date' modifier will be called 80 times which is the bottleneck. I know I could use only one time the date modifier ('D d/m/Y H:i') but then I'm not capable of styling the time.

Any suggestions on how to improve this? Creating my own template modifier? Using AJAX to load the dates when requested by the user?I'm running on Fork 3.6.6 btw. Tnx Glenn

If you always use the same date format, I would convert the date and add it to your array with results (in model.php). Right after where you fetch the data... I don't know why the date modifier takes so long to process.

Using the php date function makes it faster though it won't be translated. In my case I want "Monday 22 september 2014" to be "Maandag 22 september 2014". That's why the implemented date modifier which translates everything slows down the page load I guess.

Hmm like I said, the fastest way is probably to add the formatted date to your array with data.

About the translation: in the model.php you know which language you're using (frontend language variable), so use something like this in your model to add a date to the array:

setlocale(LC_TIME, 'nl_NL');
$date = strftime( "%h %y",strtotime("2011-12-22"));

Or try it with some Symfony components. Maybe something like this can work:

$date = new \DateTime("now");
$formatter = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE);
$formatter->setPattern("EEEE Y-M-d");
$results['date_formatted'] = $formatter->format($date);

I got this sample code from here. Of course, insert your date and frontend language as locale...

Comment

The forum is deprecated in favor of our Slack channel, which provides real-time support for your issues.

Join us on Slack here: https://fork-cms.herokuapp.com/