How to call 'parent' template?

Hi.

The most common way I’m using templates is to embed the standard template result into a new tag: span, link, etc. Is there any way to avoid coping the default template code, which sometimes can be pretty complex? Just for the illustration, PHP uses parent::myFunction() to reach the ancestor method. For example:

scheduler.templates.month_day = function(date){ var result =''; result += 'something before'; result += call_default_template(date); result += 'something after'; return result; };

Hello,

Do you want to set any styles to parent element? You can wrap date in new container and set it required styles:

scheduler.templates.month_day = function(date){ return '<div class="new_class">'+call_default_template(date)+'</div>'; };

My problem is I can’t find a way to execute the original template, my attempt :

scheduler.templates.month_day = function(date){
    return  '<div class="new_class">'+scheduler.templates.month_day(date)+'</div>';
};

says too much recursion.

What do you mean by ‘the original template’?

If you mean that template is executed as many times as there elements on page (amount of month’s days in this case), it’s default template behaviour.

I mean the default template function:

scheduler.templates.month_day = function(date) { if (this._mode == "month") { var label = date_to_str(date); if (date.getDate() == 1) { label = scheduler.locale.date.month_full[date.getMonth()] + " " + label; } if (+date == +scheduler.date.date_part(new Date())) { label = scheduler.locale.labels.dhx_cal_today_button + " " + label; } return label; } else { return old_month_day.call(this, date); } };

I’d like to avoid coping all the code into my CUSTOM scheduler.templates.month_day.
I want to wrap the default template result into my custom tags for example.

You were close, you should be able to do as follow:

var dhtmlx_month_day = scheduler.templates.month_day;
scheduler.templates.month_day = function(date) {
    return  '<div class="new_class">' + dhtmlx_month_day.call(this, date) + '</div>';
};

Thank you Gregoire, works like a charm. :slight_smile: