Template Absolute and Relative paths. What does that mean?

  • This is a bit sparse of a question. Please elaborate.
    – benmarks
    May 12 '13 at 16:47

An absolute path is from the upper most level of the directory tree. Ie. / or C:\

Eg. /home/sonassi/www/index.php

A relative path is relative to the current working directory. In the case of a web server, that would be the document root. Ie. In PHP $_SERVER['DOCUMENT_ROOT']

In the example above the document root is /home/sonassi/www - making the relative path to index.php just ./index.php or index.php. The leading ./ just denotes the current directory.

You should always use relative paths for cross-platform compatibility

Eg. Magento uses a relative path for the ./app/Mage.php include in index.php - which means even if you change server, it will still look only in the app subdirectory for the file.

But if they had defined an absolute path, eg. /home/sonassi/www/app/Mage.php - then it means if you ever moved servers - and the document root was no longer /home/sonassi/www - then the hardcoded path would no longer be valid.

Absolute paths have their place - but as far as Magento templates are concerned (ie. definitions in XML files, they should always be relative)

Not the answer you're looking for? Browse other questions tagged or ask your own question.