Planning / Designing Config Files and Hooks

I’m working on a project that includes template files for specific data categories. These templates do most of the work, but there are some global UI elements (e.g. navigation bars) that should be displayed across all pages. The question is kind of basic, but it’s new for me so I’d appreciate hearing your advice.

From here on out:

  • “config” refers to a config file of yet-unknown format.
  • “template.php” refers to a template that formats data of a specify category.
  • “global-ui-element” refers to a user-interface element that should be added to every template.php.
  • “global-ui-element.php” and “global-ui-element.css” refer to the paths of a global ui element.

I’d like for the addition of new template files - by people other than myself - to be as easy as possible, so I don’t want to require every “template.php” to have a large section filled with links to all the global-element stylesheets or require the template creator to figure out where to include/require_once/whatever each “global-ui-element.php” file.

My planned solution involves a config file and lots of loops:
The config file would have one constant array with the name of each global-ui-element, and then subsequent constant arrays that specify the location of the global-ui-element’s .CSS and .PHP files. To load them in each template file, I would write scripts that act kind of like hooks in wordpress.

Included in the of every template.php would be a “loader_styles.php” script that:

  • Parses the config file and gets the .css paths for each global-ui-element
  • builds and prints a link “<link rel=stylesheet… href=‘[$global-ui-element.css]’ />”

There would be a “loader_elements” script (if I can’t come up with a better title) that then adds the global-ui-element.php files to the top of the in each template.php.

I’ve got the majority of the code up and running, but I’m not satisfied with the format of the config file (currently a .php file using constants).

Summary:
Basically, I want to make sure that it’s easy to both add new template.php files, and to add new global-ui-elements without having to update each template. [For the config file] I’m looking at using YAML instead of PHP, and creating a new .php script to parse it for whatever the caller (e.g. “loader_stylesheets.php”) requests.

This should allow for users to easily implement the global ui elements in their own custom template files, and/or to easily define new global UI elements and ensure they’re loaded on the correct pages.

I’d like to know if anyone has any tips/tricks/advice, especially regarding the design of application config files.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.