Header and footer files - Page 1 -...

User 2822489 Photo


Registered User
7 posts

Currently RSD have no option to add headers and footers to all pages automatically. This is a major drawback to an otherwise excellent software.

In order to work around this limitation I have created a PHP script that will automatically add header.html on the top and footer.html on the bottom of all html pages. The script also validates and fix the HTML syntax with Tidy (http://www.html-tidy.org/).

In order to use the script:
    Your server must support PHP 5
    Make sure the extention php_tidy.dll is enabeled in your php.ini on the webserver
    Unzip and place the enclosed files in the same directory as your html files on the server
    Create a header file in RSD and name it header.html
    Create a footer file in RSD and name it footer.html
    Export/upload your new header/footer to the server

NOTE: If you already the htaccess file on your webserver, do not owerwrite. Merge the content of the two .htaccess files instead.

NOTE: The HTML validation/fixing by Tidy could break some functionality in your site. But if you are using valid HTML this should not be a problem.
Attachments:
User 2822489 Photo


Registered User
7 posts

A new version of the script is encloced. The following issues are fixed:
    Added support for HTML5 tags
    Multiple Title tags are automatically removed
    Empty description and keyword META tags are automatically removed

Note: The Apache rewrite module need to be enabled on your webserver for this script to work. In php.ini the extention php_tidy.dll must be enabled.
Attachments:
User 122279 Photo


Senior Advisor
14,622 posts
Online Now

Thans for posting. I have not had time to check out your files yet, but I presume it must be something to the same effect as php includes, only that you don't have to use .php file extension?

Can your script be used for other parts of a website too?, like the navbar or a permanent sidebar?
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 2822489 Photo


Registered User
7 posts

Currently the script will only add headers and footers. Sidebars are not supported.

This is how it works:
  • Every time the server request a HTML file the request is redirected to the script. The script will add the file "header.html" on top of the page and the file "footer.html" at the bottom. This is very similar to using PHP includes.
  • Now we have the HTML code of three pages mixed together causing multiple head and body sections, duplicate tags and multiple title tags. So the next step for the script is to clean up this mess by merging the content of all head sections into one and removing duplicate lines and redundant title tags.
  • Finally the code is processed, validated and fixed by HTML Tidy (http://www.html-tidy.org/). Tidy corrects and cleans up HTML documents by fixing markup errors and upgrading the code to modern W3C standards.

I'm attaching latest version of the scripts containing a couple of minor bug fixes, support for more HTML5 tags and better compatibility with RSD


Attachments:
User 2822489 Photo


Registered User
7 posts

Note: If you are looking for a simpler approach without any server side code merging and fixing, you can use a simple JavaScript include script (courtesy of http://www.w3schools.com.)

Link to the enclosed JavaScript within a HTML section where you want the header.html content to appear:

<div w3-include-HTML="header.html"></div>
<script src="w3-include-HTML.js"></script>
Attachments:
User 431141 Photo


Registered User
78 posts

Ronny,
If I understand your post, I can create a separate single page RSD website of just the header (menu & slider), saved as "header.html", put it to the same root folder as the main website, where each page of the main website has the HTML section and header code as you described, and it will appear in the final browser window as if it was part of the main website in the first place... is that right?
=Steve=
User 431141 Photo


Registered User
78 posts

... and if it's that simple, couldn't the great programming geniuses at CC incorporate this functionality into RSD? (
=Steve=
User 122279 Photo


Senior Advisor
14,622 posts
Online Now

I think, if you have a one page site, there is no need for this script, because you have just one header and one footer. No problem keeping those updated. But if you create a 'normal' website with several pages, then it would be good having to update/edit the header/footer only in one place.
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 232214 Photo


COO
827 posts

Ronny Skog wrote:
Currently RSD have no option to add headers and footers to all pages automatically. This is a major drawback to an otherwise excellent software.

Thanks for the script Ronny. I think this has been talked about here and there....we will be adding this feature for sure. No ETA yet but it will happen...

:cool::P
The future of web layout has arrived and it's called CSS Grid. CoffeeCup helps you to get ready with a free guide, the Grid Builder app plus cool demos & themes.
User 2822489 Photo


Registered User
7 posts

Steve Ravner wrote:
Ronny,
If I understand your post, I can create a separate single page RSD website of just the header (menu & slider), saved as "header.html", put it to the same root folder as the main website, where each page of the main website has the HTML section and header code as you described, and it will appear in the final browser window as if it was part of the main website in the first place... is that right?


Yes Steve, you can create one "header.html" page, put it in the same folder as the rest of your website along with the script and it will appear on top of all your HTML pages as if it was a part of those pages. Your server/webhost must support the Apache rewrite module and the PHP extention php_tidy.dll (otherwise use the JavaScript instead of my script).

Its good to hear that CoffeeCup software will add this much needed feature. Its not hard to do so hopefully they will add this sooner rather than later :) In the mean time my script should provide a workaround if you have a large website and need the same header/footer to display on all pages.


Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.