Koha as a CMS

From Koha Wiki

Jump to: navigation, search
Home > Documentation
Home > Koha Versions > 3.0
Home > Koha Versions > 3.14
Home > Koha Versions > 3.16

Contents

Setup

These are instructions for taking a default install of Koha 3.4 or later (the page has been revised based on a 3.14.9 installation) and allowing it to function as a little content management system. This will allow a library to publish an arbitrary number of pages based on a template. This example uses the template for the main opac page, but you could just as well use any template you wish with a bit more editing. This may be appropriate if you have a small library, want to allow librarians to easily add pages, and do not want to support a complete CMS.

  • On /usr/share/koha/opac/cgi-bin/opac/ copy opac-main.pl to pages.pl.
  • Edit pages.pl in an editor
  • At approximately line 33 change this code: 

   template_name  => "opac-main.tmpl",

  • To this code:

   template_name  => "pages.tt",
  • At approximately line 62 after this code:
$template->param( 
           koha_news       => $all_koha_news, 
           koha_news_count => $koha_news_count,
           display_daily_quote => C4::Context->preference('QuoteOfTheDay'),
           daily_quote         => $quote,
           );


* Add these lines:

Warning : copy/pasting this into vi can insert an extra line with non visible characters that will yield the folowiwng error : Software error: Unrecognized character \xE2 in column 1 at /home/koha/kohaclone/opac/pages.pl line 63, <DATA> line 581. Just delete the empty line.

           my $page = "page_" . $input->param('p');            # go for "p" value in URL and do the concatenation
           my $preference = C4::Context->preference($page);    # Go for preference  
           $template->{VARS}->{'page_test'} = $preference;     # pass variable to template pages.tt
  • Note pages.pl file must have Webserver user execution permissions, you can use chmod command if you are actually logged in as such user:
      $chmod 755 pages.pl

Editing the pages template

The file to create / edit for the pages template will depend on your opacthemes system preference setting i.e. bootstrap or prog (deprecated) or ccsr (deprecated)

Editing 'bootstrap' theme template (current)

  • Copy /usr/share/koha/opac/htdocs/opac-tmpl/bootstrap/en/modules/opac-main.tt to /usr/share/koha/opac/htdocs/opac-tmpl/bootstrap/en/modules/pages.tt
  • Edit /usr/share/koha/opac/htdocs/opac-tmpl/bootstrap/en/modules/pages.tt
  • At approximately line 61, change this:

    [% IF ( OpacMainUserBlock ) %]<div id="opacmainuserblock">[% OpacMainUserBlock %]</div>[% END %]
  • 
To this:
    [% IF ( page_test ) %]<div id="opacmainuserblock">[% page_test %]</div>[% END %]

Remark: You may wish to disable your News block of these CMS style pages e.g. when you do not want it displayed on the CMS style pages or where the News block is long enough that it actually makes the 'page_test' include scroll outside the default viewport dimensions. In that case, remove the following code from your pages.tt template.

        [% IF ( koha_news_count ) %]
            <div id="news">
                <table class="table table-bordered">
                    [% FOREACH koha_new IN koha_news %]
                        <thead><tr><th>[% koha_new.title %]</th></tr></thead>
                        <tbody><tr><td><p>[% koha_new.new %]</p>
                        <p class="newsfooter"><i>(published on [% koha_new.newdate %])</i></p></td></tr></tbody>
                    [% END %]
                </table>
            </div>
        [% END %]

Editing 'prog' theme template (deprecated)

  • Copy /usr/share/koha/opac/htdocs/opac-tmpl/prog/en/modules/opac-main.tt to /usr/share/koha/opac/htdocs/opac-tmpl/prog/en/modules/pages.tt
  • Edit /usr/share/koha/opac/htdocs/opac-tmpl/prog/en/modules/pages.tt
  • At approximately line 40, change this:

    <div id="opacmainuserblock" class="container">[% OpacMainUserBlock %]</div>
  • 
To this:
    <div id="opacmainuserblock" class="container">[% page_test %]</div>

Building your first 'page'

  • In the browser go to Home › Administration › System Preferences > Local Use and add a New Preference called "page_test"
  • Fill it out as so
    • Explanation: test page for pages tiny cms
    • Variable: page_test
    • Value: Lorem ipsum
    • Click the TextArea link (or enter "TextArea" into the input field below it)
    • variable options (last field): 80|50
  • In a browser go to http://youraddress/cgi-bin/koha/pages.pl?p=test The page should come up with the words "Lorem ipsum" in the main content area of the page. (replace "youraddress" with localhost, 127.0.0.1, or your domain name depending on how you have Apache set up.)
  • To add more pages simply create a system preference where the title begins with "page_" followed by any arbitrary letters. You can add any markup you want as the value of the field. Reference the new page by changing the value of the "p" parameter in the URL.

Troubleshooting

If you have problems check file permissions on pages.pl and pages.tt. They should have the same user and group as other Koha files like opac-main.pl.

Bonus Points

Instead of using the address http://<your_OPAC_address>/cgi-bin/koha/pages.pl?p=test you can shorten it to http://<your_OPAC_address>/pages.pl?p=test Just at approximately line 12 on file /etc/koha/apache-shared.conf add this line:

ScriptAlias /pages.pl "/usr/share/koha/opac/cgi-bin/opac/pages.pl"

Then restart Apache.

Personal tools