Innovative Computer Solutions,
Development & Technical Support

07975 997026 • enquiries[delete-me]@[delete-me]harpanet.com

User Tools

Site Tools


programming:php:codeigniter:hats:rename_folders

hArpanet Template System (hATS) for CodeIgniter

v2.1.1

hATS PARTS & THEME REQUIREMENTS

hATS (by default) expects the following paths for certain files depending on the function called.

Only the /theme path can be changed, the others are hard-coded. eg. the tplStylesheet() function expects the stylesheet to be found in the css folder of the current theme.

  1. /hAts/theme folder in your webroot (this path can be changed in your controller)
  2. /hAts/theme/[theme_name]/css folder – contains theme specific css files
  3. /hAts/theme/[theme_name]/img folder – contains theme specific images
  4. /hAts/theme/[theme_name]/js folder – contains theme specific javascript files
  5. /hAts/parts folder - contains all view parts (small blocks of pHTML) (this path can be changed in your controller)

RENAME THE DEFAULT FOLDERS

To ensure your own theme and parts files are not overwritten when hATS is upgraded, you must first rename the hAts_default parts and theme folders.

The THEME folder

/hAts/theme/hAts_default

Simply rename hAts_default to a name appropriate to your theme. eg. my_theme or christmas etc. then insert appropriate images, javascript or CSS changes as required.

You may also wish to keep the hAts_default folder and simply make a copy of it so that you can use it each time you want to create a new theme from the original.

The PARTS folder

/hAts/parts/hAts_default

Renaming this folder depends on how you want hATS to handle your Part files.

  1. Using the Class Name

    In the hAts_example Controller, the following line is commented out in the __constructor:

     tplSet('parts', strtolower(get_class($this))); 

    If you uncomment the above line, the name of the Parts folders will be set automatically based on the name of the Class (Controller) from which they are used.

    In the hAts_example Controller, you would need to rename your hAts_default folder to hats_example in order for hATS to find the correct Parts.

  2. Using your own Naming Convention

    You are free to use any naming convention (or randomness) that suits you. It is highly recommended that you use a structure that bares some resemblance to the Controller it relates to.

    eg. If we are building a Log_in Controller and associated parts, it is recommended you create a Parts folder like login.

    Then, in your Method that handles display of the user login page, say login_page() you set the Parts folder as:

     tplSet('parts', 'login'); 

    However, if you wanted different pages for User logins and Admin logins, you could create the following folder structure:

    /hAts/parts/login/
    /hAts/parts/login/admin
    /hAts/parts/login/user
    /hAts/parts/login/reminder

    I've also thrown in a reminder folder for good measure. Now, in each of your Log_in Controller Methods, you would set the appropriate Parts path…

    admin_login()

     tplSet('parts', 'login/admin'); 

    user_login()

     tplSet('parts', 'login/user'); 

    pw_reminder()

     tplSet('parts', 'login/reminder'); 

Parts Traversal

If you have specified a Parts folder, say tplSet('parts', 'login/admin'); then hATS initially looks in the specified path for its Parts files.

If hATS doesn't find the file, it traverses the folder path (ie. looks in the parent folder, grandparent folder, etc.) until it finds the specified Parts file.

So, the following code…

tplSet('parts', 'login/admin');
tplAddPart('body_content');
  • would cause hATS to try and use the file /hAts/parts/login/admin/body_content.phtml
  • If that file did not exist, hATS would next look for /hAts/parts/login/body_content.phtml and so on.

Because of this, you can create default content/structure once, in a parent folder, then only override the necessary Parts in the child folders.

So, in the Log_in example Methods above, we could instead decide that /hAts/parts/login will have all the Parts necessary to create the login page structure and show the user_login() page (in which case we would dispose of /hAts/parts/login/user entirely).

Then, for the admin_login() page we simply copy /hAts/parts/login/body_content.phtml into /hAts/parts/login/admin/body_content.phtml and make the necessary text/style changes. hATS will automatically find the other Parts for the page (eg. head.phtml, body_open.phtml, etc.) by traversing the parent folders.

(If hATS fails to find a part by the time it reaches the root folder / then a warning will be shown where the part should have been displayed.)

PARTS RECOMMENDATION

Because of the automatic traversal/override of Parts, you should:

  • Copy all .phtml files from /hAts/parts/hAts_default and place them in /hAts/parts

This will ensure that hATS always has a fallback Parts file to find if one doesn't exist in a more specific child folder.

CHANGING PATH SETTINGS

As mentioned in REQUIREMENTS section above, it is possible to change to location of the theme and parts folder locations. To do this is as simple as setting new locations in two reserved hAts variables.

themePath

  tplSet('themePath', '/includes/theme');

This would change the location for all your theme files from the default /hAts/theme/ to /includes/theme/.

partsPath

  tplSet('partsPath', '/includes/parts');

This would change the location for all your parts files from the default /hAts/parts/ to /includes/parts/.

DO IT YOURSELF

OK, you've made it through all the setup blurb, so it's time to go-it-alone…

Comments



O R I L W​ O W D O L Q N
programming/php/codeigniter/hats/rename_folders.txt · Last modified: 14/07/2014 20:47 by harpanet