The page header (or banner) is automatically included on all of your website’s client facing pages. The page header will generally have a menu and other elements as required.
For example; a quick search box, a login / logout link, a logo and so on. The default header is generated automatically and it will contain elements that you have selected in your configuration settings – but depending on the user’s permissions and session state. Although there are many settings provided for the standard page header, if you want more control and flexibility, then you can create your own page header and menu, which is explained in this article.
Even if you create a custom header, you can still use the menu that you have configured in Back office with the xs tags and functions. This has the advantage that the menu can be changed without having to change the actual code.
Recommended reading
- Using the Code editor
- Using custom CSS
- Infradox XS customisation
- Creating a custom Home page
- Building website menus
Building a custom page header
Go to Site configuration and click on Code editor. Next choose Page header HTML in the dropdown box at the top of the page. If there’s no custom HTML yet, then the editor will be empty. If a custom header already exists, the code will be displayed and you can see who last changed it and when. Click on the revision link to view and/or restore previous versions of the code. A maximum of 50 revisions can be stored.
Embedding CSS in your custom header
You can embed CSS in the code that you enter for your header while you are developing and testing. When you are done, you should remove the CSS from the page header template, and you should then put it in the Custom CSS instead. To embed CSS, use the
tags at the top of the code. For example:
HTML
It is best to use the classes that already exist. Use a browser with developer extensions installed (we recommend Chrome) so that you can inspect the elements used by the standard header. You can also click “view page source” to see what the standard header looks like while browsing your website in a separate window. Also, some of the script on the pages depends on certain class names and id’s. For instance the dropdown menu script.
The main menu is an unordered list (UL) and the menu items are list items (LI). The unordered list(s) must have the class menuitems for the mobile device menu to work.
A custom banner/header with the default XS menu
You can develop a custom header/banner, while still using the default menu (by use of the menu builder) – as opposed to manually creating the menu. The advantage of using this option, is first of all that it’s much quicker and simpler to develop a custom header this way, but also that you can still configure the menu and related settings using the Back office functions. Using the standard menu’s also allows for more efficient caching.
You can load a starting template by clicking Load example and the select the file default-banner-1.txt. It is recommended that you first configure the standard menu and banner settings (without enabling the code for your custom page header). If you then enable the custom page header, the resulting HTML will look the same as the standard version. You can then start changing the template as required.
In the example template (default-banner-1.txt) you’ll see this code fragment:
The xs tags include the standard HTML code for the left side of the menu (xs-leftsidemenu.inc) and for the right side of the menu (xs-rightsidemenu.inc). Note that if you want to use the standard menu, then you must add the property xsmenu=”1″ to the mainMenuContainer div container element. Like so:
The standard HTML code for the dropdown menus is included by use of the tag:
The above tag will output all the required HTML based on the settings that you have configured.
You can of course create your own pulldown menu’s and as many as you need. If you want to control how and where dropdown menu’s are displayed then you can add the function “onpulldownmenu” to the client object in your script – see below examples:
onpulldownmenu: function(li,menu) { /* li is the list item, menu is the pull down menu */
menu.show().position({of:li,my:"center bottom-15",at:"center"}); /* A) show the menu centered underneath the menu item */
//or menu.slideDown(200).position({of:li,my:"center bottom-15",at:"left"}); /* B) slide down the menu left aligned with the menu item */
//or menu.fadeIn(500).position({of:li,my:"center bottom-15",at:"center"}); /* C) fade in centered underneath the menu item */
}
The Infradox script uses JQueryUI to position and display the pulldown menu’s, so you can use all supported animations et cetera.
Furthermore, you’ll see this code fragment in the example template:
} ?>
This takes care of including the quick search HTML code in the position that you have configured in Back office. You can of course simply remove the code fragments and add the
to include the HTML in the position where you want it to appear.
Creating your own menu
You can of course take things into your own hands entirely. Have a look at the example code below that doesn’t use the XS tags to insert the standard menu:
...
,
} ?>
...
Using the tags to insert the entire menu have the advantage that checking if a user is logged in or not – and hiding/displaying HTML accordingly, is automatic. If you create a menu yourself, then you’ll have to check the user status also. In the above example, the guest conditions are used to hide or show HTML depending on who’s visiting the website.
If you have created dynamic subdomains
Some of the subdomain settings will not take effect automatically if you use a custom header and menu. You can however control everything from within your code. Use subdomain conditions to include or exclude page fragments, apply different CSS and so on.
Examples:
You can use the conditions as shown in the above examples to show or hide html elements, to apply special CSS and so on.
You can also use the following tags for subdomains:
to output the active subdomain name.
or
to output the subdomain id. If no subdomain is active (i.e. www) then this will output 0.
You can use this to e.g. apply different CSS based on the subdomain. The example below outputs … class=”subdomain0″ or class=”subdomain1″ etc, so that you create and apply different classes based on which subdomain is active.
Step by step
This sections explains step by step how to load the default template and how to make changes to it. First load the template default-banner-1.txt into the code editor. This will output the same html as you would get without using a custom template. This template uses the menu that you have built with the menu builder, it inserts the quick search box html and it uses all the settings that you have configured in backoffice / site configuration.
As you can see, the template has instructions and conditions that you don’t need if you know what items you want to appear where. So we can now remove what we don’t need. Fewer instructions/conditions means that there’s less to parse so the output will be faster. Note that changing settings in backoffice will of course no longer have an effect as a result.
The settings men_loglogpos and mem_logoutpos are used to configure where to position the log in and log out links, and the setting men_logregpos is used to configure where to position the register link. If we know where we want these links to appear, then we can change the template accordingly by removing the conditions for these settings. These links appear in a div (with id userInfo) and we want this div on the right side in the banner. The class searchpos0 has CSS to make it appear there. So we can remove the tag and replace it by the number 0.
Note that if you don’t want these links in the page header but for example in the menus instead, then remove them from the template and use the menu builder to put the items where you want them to appear.
Furthermore, we know where we want the logo so we can remove the inline style from it and we can then add the CSS for this to the custom CSS file. We could of course replace the constants with normal text too, but this is not recommended. By keeping the constants, we can change the text/labels without having to edit the template and if the website supports multiple locales then the correct language will be automatically used in the resulting HTML.
Our website supports multiple languages, so we can remove the condition that checks if there is more than one language configured in backoffice (loc_localecount). The localemenulist() tag outputs the configured locales for the language selection menu, so we do want to keep that. If your website doesn’t support multiple locales, then you can of course remove everything that has to do with that (e.g. you can remove the div localedropdown and everything in it).
The tag that applies a margin with inline style to the left side menu can also be removed (rproperty(‘mnu_left’,’0′)).
Finally, we want the quick search box to appear on the right side of the banner, so we can remove the code with the xsp_searchpos condition too (xsp_searchpos==1 puts the quick search HTML in the banner on the right, xsp_searchpos==0 puts it in the banner underneath the menu and on the left).
Below is the template after the above changes (note that this is also available as a default-banner-2.txt).
We want a large search box on the home page. We can use the quicksearch widget for this. To learn more about creating a custom page, read Creating a custom Home page. The quicksearch html – that is inserted in the header with the tag html(‘quicksearch.inc’) – has elements with id’s and these id’s are important for the search script. So on the home page, we don’t want the quick search box to appear in the banner – or we would have duplicate id’s which will cause the script to fail. The condition tag server(‘homepage<>1′) takes care of this.
The html below shows how we exclude the quick search box when on the home page:
Adding a menu item to the HTML
You can add a menu item to the HTML without using the menu builder. Menu items are list elements containing links. The example below shows how a simple menu item is added after the generated menu html. You should of course use constants or locale conditions if your website supports multiple locales.
Note that the list item must have an id that starts with lmenu_ followed by a unique number, and that the link must have an id that starts with menu_ followed by the same number.
Although not recommended, you can of course write your own menu this way without using any of the xs tags.
Adding a submenu item to the HTML
The menu builder lets you add one extra dropdown menu. If you need more submenu’s, you can simply add the HTML. Using the correct id’s and classes will make sure that the default menu script will also work for your custom menu items (i.e. it will show the dropdown menu when you hover over its menu item). Below is just a simple example, actual menu’s may need more work to support localisation etc.
Adding your own HTML to replace the quicksearch.inc HTML
Provided that your HTML uses the correct id’s and classes, you can replace the quicksearch.inc HTML with your own HTML. Below is example HTML to replace the quicksearch.inc HTML.
FAQ
- I don’t want a menu at all in the page header. Is that possible?
That’s of course possible, just remove the menu html and tags from your template. You will then have to add links to other pages/templates to access certain pages yourself. - I only want a single menu, how do I do that?
You can use the menu builder to add all items to either the left- or right side menu. Then remove the html for the menu that you don’t want to use – i.e. html(‘xs-leftsidemenu.inc’) or html(‘xs-rightsidemenu.inc’) - I don’t want to use the menu builder, can I create a menu myself?
That’s possible. You’ll need to add the html and script yourself. The xs menu tags generate HTML with specific id’s and classes for the script to work. Use your code inspector to see what the generated HTML looks like. - There’s only one item for a custom drop down menu. Can I add more menu’s?
You can add your own html and script to add as many menu’s as you want. - How do I remove the quick search box on the home page?
Use the condition server(‘homepage<>1′) as explained above.