Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FullCalendar display HTML in event title

I am updating my Fullcalendar install to V4. I am feeding mine via JSON and I have HTML (some FontAwsome Icons) in my event title. Here is my old V3 code to render my elements:

$(function() {
  $('#calendars').fullCalendar({
    events: '/activities/calendar.json',
    contentHeight: 750,
    displayEventTime: false,
    header: {
      left: '',
      center: 'title',
      right: 'today prev,next'
    },
    businessHours: {
      dow: [1, 2, 3, 4, 5]
    },
    handleWindowResize: true,
    eventLimit: 2,
    eventLimitClick: 'popover',
    eventRender: function(event, element) {
      element.find('.fc-title').html(event.title);
    }
  });
});

The eventRender: is what fails. The new docs don't clearly explain how I my convert this to the new version. With this code in place my calendar simply fails to load with json parse error in the console. If I remove it it works but my HTML is rendered as plain text. I am sure I am missing something obvious and easy here. My JS skill set is not that great.

like image 507
Dan Tappin Avatar asked Nov 06 '25 18:11

Dan Tappin


1 Answers

As of FullCalendar v5 you can use eventContent.

document.addEventListener('DOMContentLoaded', function() {
   let calendarEl = document.getElementById('calendar');
   let calendar = new FullCalendar.Calendar(calendarEl, {
      initialView: 'dayGridMonth',
            
      events: [
            {
                "id": 1,
                "title": "First Line<br>Second Line",
                "start": "2022-06-04",
                "end": null,
                "allDay": true,
                "editable": true,
                "className": "badge-soft-warning",
           
            }
        ],

      eventContent: function( info ) {
          return {html: info.event.title};
      }

    });
    calendar.render();
})
like image 112
Fevzi Altay Güvenli Avatar answered Nov 09 '25 12:11

Fevzi Altay Güvenli