phptemplae page template based on uri


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. function _phptemplate_variables($hook, $vars) {
  3. switch ($hook) {
  4. case 'page':
  5. // this is a hack to suggest template files based on request uri
  6. // to suplement standard arg-based suggestions. this allows for
  7. // aliases to be taken into account
  8. $request_uri = $_SERVER['REQUEST_URI'];
  9. $request_uri = str_replace('my_statement','application',$request_uri);
  10. $suggestion = 'page';
  11. $suggestions = array();
  12. $matches = explode('/',$request_uri);
  13. $num_matches = count($matches);
  14. //ignore the first match, since the URI is of the form /path/to/uri
  15. for ($i=1;$i<$num_matches;$i++) {
  16. $suggestion .= '-'. $matches[$i];
  17. $suggestions[] = $suggestion;
  18. }
  19. $vars['template_files'] = $suggestions; // array($section_template);
  20. break;
  21. // any additional code here
  22. }
  23. return $vars;
  24. }
  25. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.