Hi,
I would like to have a calendar page on my nikola site with my free/busy times on it. I found the FullCalendar JavaScript library <
http://fullcalendar.io>, which is pretty amazing, and decided to integrate it.
What I wanted to do was write a ReST directive plugin so that in my in my calendar.rst file I could have
.. calendar::
:opt1: foo
:opt2: bar
etc, and have the plugin do all the work. But I had trouble generating the HTML in the proper order. To use fullcalendar, .
* one or two CSS <link>s need to be inserted into the document <head>.
* a simple <div id="calendar"></div> tag goes into the page <body>.
* the fullcalendar.js script needs to go after jquery and moment.js are loaded. In the bootstrap3 theme this occurs at the end of the page content.
* calendar creation code like the below needs to go after fullcalendar.js (or maybe just after jquery):
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
defaultView: 'agendaWeek',
header: {
left: 'title',
center: 'agendaDay,agendaWeek,month',
right: 'today prev,next'
},
weekends: false,
businessHours: true,
// ...
}
})
});
</script>
My plugin's run method can create the div, no problem. But for the extra html and scripting, I ran into trouble. First, I tried using template hooks in my plugin's `set_site` method, but then I discovered that this extra html ended up on every page, not just the calendar page. Then I tried adding those template hooks to the plugin's `run` method, but they didn't seem to get recognized there.
Then I found the documentation on creating custom pages and made a custom calendar.tmpl derived from story.tmpl. That accomplished what I wanted. Except now the fullcalendar configuration code is in the template, and the plugin does almost nothing. Kind of unsatisfying.
What's the "nikola way" to do this? Is there a way I can put calendar configuration options into the RST file and pass them to the template?
Thanks in advance for any advice.