[Koha] Include dynamic content in opac main page

Alvaro Cornejo cornejo.alvaro at gmail.com
Tue Jul 7 11:25:14 NZST 2020


Hi

We found a solution that satisfied our requirements:

We added a script tag in each place we need to display dynamic content  (in
our case: IntranetmainUserblock and OpacMainUserBlock)

<script src="/dynamiccontent/file-nnn.html"></script>

file-nnn.html has all the html data/content we want to show in the
mentioned sections. CSS/styles, as does not change is either in usercss or
in  IntranetmainUserblock / OpacMainUserBlock depending on whether is
global reaching or local reaching.

file-nnn.html is a normal html file but  there are some important
considerations to be aware of:

- ALL included content ( html / styles / css / etc.) MUST be within a:
document.write("   and a    ");  statement
- ALL and each line feed within the document.write statement must be
escaped with a \ (back slash) including the document.write(" line
-  Special characters like ", ´, \, etc must also be escaped with  \
- Files location shall be within koha root path:
      /usr/share/koha/intranet/htdocs/
      /usr/share/koha/opac/htdocs/
- Files must have at least -rw-r--r-- permissions.

We have some crons  that run processes like stats, reports, news feeds, etc
and updates those file-nnn.html files. This way that info is automatically
updated into the places we want to show them through the script tag.

I'm sure there is a more professional way to do this, but for a staff with
barely dev knowledge it works. We are open to better/more efficient ways to
do this.

Hope is useful or inspires someone.

Regards,

Alvaro


|----------------------------------------------------------------------------------------|
 Stay safe / Cuídate/  Reste sécurisé
*7* Switch off as you go / Apaga lo que no usas /  Débranchez au fur et à
mesure.
 *q *Recycle always / Recicla siempre / Recyclez toujours
 P Print only if absolutely necessary / Imprime solo si es necesario /
Imprimez seulement si nécessaire


Le lun. 6 juil. 2020 à 16:55, Tim McMahon <tmcmahon at wlpl.org> a écrit :

> You should use htdocs instead of cgi-bin for HTML files, but I'm not
> sure how good of an idea it is to put custom content in a Koha directory.
>
> On 7/3/20 3:50 PM, Alvaro Cornejo wrote:
> > Hi
> >
> > We want to include some content that is generated daily in html format
> into
> > the main opac/intranet pages. We tried to use this (snip) code in
> > IntranetmainUserblock  and OpacNavBottom but can´t get the content to be
> > shown
> >
> > <script src="jquery.js"></script>
> >    <script>
> >      $(function(){
> >        $("#includedContent").load("DynamicCode.html");
> >      });
> >    </script>
> > ...
> >    <div>
> >    ...fixed content...
> >    <div id="includedContent">Changing content</div>
> >    ...fixed content..
> >    </div>
> >
> >
> > My guess is that "DynamicCode.html" file is not in the right place to be
> > read by koha or I´m not specifying the right path to it. We placed it in
> > intranet/cg-bin/ and opac/cgi-bin but no success. DynamicCode.html is
> > own by root but has read permit for everybody (-rw-r--r--) .
> >
> > We tried to split the snip code and place the <script> part into UserJS
> > preferences and keep display <div> part into UserBlock  but that doesn't
> > work either.
> >
> > What are we missing?
> >
> > Regards
> >
> > Alvaro
> >
> >
> |----------------------------------------------------------------------------------------|
> >   Stay safe / Cuídate/  Reste sécurisé
> > *7* Switch off as you go / Apaga lo que no usas /  Débranchez au fur et à
> > mesure.
> >   *q *Recycle always / Recicla siempre / Recyclez toujours
> >   P Print only if absolutely necessary / Imprime solo si es necesario /
> > Imprimez seulement si nécessaire
> > _______________________________________________
> >
> > Koha mailing list  http://koha-community.org
> > Koha at lists.katipo.co.nz
> > Unsubscribe: https://lists.katipo.co.nz/mailman/listinfo/koha
>
> --
> Tim McMahon
> West Liberty Public Library
> 319-627-2084
>
> _______________________________________________
>
> Koha mailing list  http://koha-community.org
> Koha at lists.katipo.co.nz
> Unsubscribe: https://lists.katipo.co.nz/mailman/listinfo/koha
>


More information about the Koha mailing list