PostNuke: A Flexible Open Source Content Management System
home | forum | international support | contact us

Documentation Wiki

Using base url and different entrypoint settings and how to adjust your modules / templates accordingly


Problem #1

Some javascript files, eg. the Lightbox, use relative paths to images, which will fail in case of short urls in directory style being enabled. We can avoid this by making the paths absoute, but for this we need to know the base url of the instalallation. In PHP, we can use pnGetBaseURL?() in this case, but the browser, where the javascript is executed, is unable to determine this correctly.

Example code (taken from lightbox.js)
var fileLoadingImage = "javascript/ajax/lightbox/loading.gif";


Problem #2

The usual entrypoint for PostNuke is index.php - all urls start by calling this file. If you want to change this, you can do this in the settings: Eg. copy index.php to start.php and configure start.php to be your entrypoint.

Note: If you are going to remove index.php or if you intend on using index.php for another script or purpose, change the entry point in your AdminPanel? first.
Unfortunately in most cases index.php is hardcoded in most modules, either in the PHP code or the templates, eg

return pnRedirect('index.php');


or

var url = 'index.php';


This will break the site if your entrypoint is start.php with some special code adjustments and index.php not being available.

and how to solve it

The base url

In your javascript code use

var fileLoadingImage = document.location.pnbaseURL + "javascript/ajax/lightbox/loading.gif";


This will add the base url to the path and create an absolute path to the image.

The entrypoint

In your code use

return pnRedirect(pnConfigGetVar('entrypoint', 'index.php'));


which loads the configured value and defaults to index.php if nothing else is used.

In your template use

var url = document.location.entrypoint;


How it works

As you can see, we extended the DOM here. This will be done automatically when at least one external javascript file is being loaded using the PageUtil::addVar, eg.

PageUtil::addVar('javascript', 'lightbox');


This will add some inline javascript before the page vars get added to the output to ensure that the DOM-extension is availalbe when the external javascript is run.
The base url is set as taken from pnGetBaseURL?() which means it always ends with a slash (/).
XML Revisions of $tag
Page history :: Last Editor [ Landseer ] :: Owner [ Landseer ] ::
Valid XHTML :: Valid CSS :: Powered by pnWikka 1.0 (A wiki fork from WikkaWiki)
 

Main Menu

Extensions Database

Documentation

Development

Login





 


 Log in Problems?
 New User? Sign Up!

Donate to PostNuke