{"id":687,"date":"2013-11-27T08:32:35","date_gmt":"2013-11-27T16:32:35","guid":{"rendered":"http:\/\/galencharlton.com\/blog\/?p=687"},"modified":"2013-11-27T08:32:35","modified_gmt":"2013-11-27T16:32:35","slug":"koha-dev-tidbit-1-control-of-space","status":"publish","type":"post","link":"https:\/\/galencharlton.com\/blog\/2013\/11\/koha-dev-tidbit-1-control-of-space\/","title":{"rendered":"Koha Dev Tidbit #1: control of space"},"content":{"rendered":"<p>Space doesn&#8217;t matter, except when it does.<\/p>\n<p>The other day Koha bug <a href=\"http:\/\/bugs.koha-community.org\/bugzilla3\/show_bug.cgi?id=11308\">11308<\/a> was filed reporting a problem with the public catalog search RSS feed. This affected just the new Bootstrap theme.<\/p>\n<p>The bug report noted that when clicking on the RSS feed icon, the page rendered &#8220;not like an rss feed should&#8221;. That means different things to different web browsers, but we can use an RSS feed validation service like <a href=\"http:\/\/validator.w3.org\/\">validator.w3.org<\/a> to see what feed parsers are likely to think.<\/p>\n<p>Before the bug was fixed, the W3C validator reported this:<\/p>\n<blockquote><p>This feed does not validate.<br \/>\nline 2, column 0: XML parsing error: :2:0: XML or text declaration not at start of entity [help]<br \/>\n&lt;?xml version=&#8217;1.0&#8242; encoding=&#8217;utf-8&#8242;  ?&gt;<\/p><\/blockquote>\n<p>Of course, at first glance, the XML declaration looks just fine &#8212; the key bit is that it is starting at the <em>second<\/em> line of the response.<\/p>\n<p>Space matters &#8212; XML requires that if an XML declaration is present, it must be the very first thing in the document.<\/p>\n<p>Let&#8217;s take a look at the patch, written by Chris Cormack, that fixes the bug:<\/p>\n<pre  class=\"lang:diff\">\r\n--- a\/koha-tmpl\/opac-tmpl\/bootstrap\/en\/modules\/opac-opensearch.tt\r\n+++ b\/koha-tmpl\/opac-tmpl\/bootstrap\/en\/modules\/opac-opensearch.tt\r\n@@ -1,5 +1,5 @@\r\n-[% USE Koha %]\r\n <?xml version='1.0' encoding='utf-8'  ?>\r\n+[% USE Koha %]\r\n [% IF ( opensearchdescription ) %]\r\n <OpenSearchDescription xmlns=\"http:\/\/a9.com\/-\/spec\/opensearch\/1.1\/\">\r\n    <ShortName>[% LibraryName |html %] Search<\/ShortName>\r\n<\/pre>\n<p>This patch moves the <code>[% USE Koha %]<\/code> Template Toolkit directive from before the XML declaration to after it.  <code>[% USE Koha %]<\/code> loads a custom Template Toolkit module called &#8220;Koha&#8221;; further down in the template there is a use of <code>Koha.Preference()<\/code> to check the value of a system preference.<\/p>\n<p>But why should importing a TT module add a blank line?  By default, Template Toolkit will include all of the whitespace present in the template.  Since there is a newline after the <code>[% USE Koha %]<\/code> directive, that newline is included in the response.<\/p>\n<p>Awkward, when spaces matter.<\/p>\n<p>However, Template Toolkit does have a way to <a href=\"http:\/\/www.template-toolkit.org\/docs\/manual\/Syntax.html#section_Chomping_Whitespace\">chomp whitespace<\/a> before or after template directives.<\/p>\n<p>This means that an alternative fix could be something like this:<\/p>\n<pre  class=\"lang:diff\">\r\n--- a\/koha-tmpl\/opac-tmpl\/bootstrap\/en\/modules\/opac-opensearch.tt\r\n+++ b\/koha-tmpl\/opac-tmpl\/bootstrap\/en\/modules\/opac-opensearch.tt\r\n@@ -1,4 +1,4 @@\r\n-[% USE Koha %]\r\n+[% USE Koha -%]\r\n<\/pre>\n<p>Adding a single hyphen here means that whitespace after the TT directive should be chomped &#8212; in other words, not included in the response.<\/p>\n<p>Most of the time, extra whitespace doesn&#8217;t matter for the HTML emitted by Koha.  But when space matters&#8230; you can use TT to control it.<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-687\" class=\"share-twitter sd-button share-icon\" href=\"https:\/\/galencharlton.com\/blog\/2013\/11\/koha-dev-tidbit-1-control-of-space\/?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\"><span>Twitter<\/span><\/a><\/li><li><a href=\"#\" class=\"sharing-anchor sd-button share-more\"><span>More<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><div class=\"sharing-hidden\"><div class=\"inner\" style=\"display: none;\"><ul><li class=\"share-tumblr\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-tumblr sd-button share-icon\" href=\"https:\/\/galencharlton.com\/blog\/2013\/11\/koha-dev-tidbit-1-control-of-space\/?share=tumblr\" target=\"_blank\" title=\"Click to share on Tumblr\"><span>Tumblr<\/span><\/a><\/li><li class=\"share-reddit\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-reddit sd-button share-icon\" href=\"https:\/\/galencharlton.com\/blog\/2013\/11\/koha-dev-tidbit-1-control-of-space\/?share=reddit\" target=\"_blank\" title=\"Click to share on Reddit\"><span>Reddit<\/span><\/a><\/li><li class=\"share-end\"><\/li><li class=\"share-print\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-print sd-button share-icon\" href=\"https:\/\/galencharlton.com\/blog\/2013\/11\/koha-dev-tidbit-1-control-of-space\/\" target=\"_blank\" title=\"Click to print\"><span>Print<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Space doesn&#8217;t matter, except when it does. The other day Koha bug 11308 was filed reporting a problem with the public catalog search RSS feed&#8230;.<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-687\" class=\"share-twitter sd-button share-icon\" href=\"https:\/\/galencharlton.com\/blog\/2013\/11\/koha-dev-tidbit-1-control-of-space\/?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\"><span>Twitter<\/span><\/a><\/li><li><a href=\"#\" class=\"sharing-anchor sd-button share-more\"><span>More<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><div class=\"sharing-hidden\"><div class=\"inner\" style=\"display: none;\"><ul><li class=\"share-tumblr\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-tumblr sd-button share-icon\" href=\"https:\/\/galencharlton.com\/blog\/2013\/11\/koha-dev-tidbit-1-control-of-space\/?share=tumblr\" target=\"_blank\" title=\"Click to share on Tumblr\"><span>Tumblr<\/span><\/a><\/li><li class=\"share-reddit\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-reddit sd-button share-icon\" href=\"https:\/\/galencharlton.com\/blog\/2013\/11\/koha-dev-tidbit-1-control-of-space\/?share=reddit\" target=\"_blank\" title=\"Click to share on Reddit\"><span>Reddit<\/span><\/a><\/li><li class=\"share-end\"><\/li><li class=\"share-print\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-print sd-button share-icon\" href=\"https:\/\/galencharlton.com\/blog\/2013\/11\/koha-dev-tidbit-1-control-of-space\/\" target=\"_blank\" title=\"Click to print\"><span>Print<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"Koha Dev Tidbit #1: control of space #kohails","jetpack_is_tweetstorm":false},"categories":[10,11],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3gJ9y-b5","_links":{"self":[{"href":"https:\/\/galencharlton.com\/blog\/wp-json\/wp\/v2\/posts\/687"}],"collection":[{"href":"https:\/\/galencharlton.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/galencharlton.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/galencharlton.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/galencharlton.com\/blog\/wp-json\/wp\/v2\/comments?post=687"}],"version-history":[{"count":14,"href":"https:\/\/galencharlton.com\/blog\/wp-json\/wp\/v2\/posts\/687\/revisions"}],"predecessor-version":[{"id":701,"href":"https:\/\/galencharlton.com\/blog\/wp-json\/wp\/v2\/posts\/687\/revisions\/701"}],"wp:attachment":[{"href":"https:\/\/galencharlton.com\/blog\/wp-json\/wp\/v2\/media?parent=687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/galencharlton.com\/blog\/wp-json\/wp\/v2\/categories?post=687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/galencharlton.com\/blog\/wp-json\/wp\/v2\/tags?post=687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}