Finding _variables

I probably have some concept confused.

I need to create a fair amount of logic (building javascript for Googlemaps) and I'm putting it in a file with the same name as the view in the _variables directory so that I can pass page-specific JS into my header block

Now the question

if the view is in the main view directory and the variable file is in the _variables directory, it works perfectly
views/view.php with views/_variables/view.php

If I put the view in a subdirectory, I can't seem to get the variables file found
I've tried
views/subdir/view.php with views/_variables/subdir/view.php
views/subdir/view.php with views/_variables/view.php
views/subdir/view.php with views/subdir/_variables/view.php
And the varibles file never gets found

Is there a way to keep these organized in subdirectories, or do I have to keep all the views that need a variables file in the views directory ??

Thank you!

Comments

  • edited 4:08AM
  • edited 4:08AM
    NeoArc is correct. FUEL only looks one URI segment (the controller segment level) deep for the _variables files and does not look in subdirectories. However, in your _variables/view.php file you can add a $pages variable right below your $vars variable that contains an array of variables to apply to a page. The key value is the pages URI path:$pages['subdir/view'] = array('my_js' => 'my_js_value');
    You can also use regular expression just like routes to map variables. Below is an example of mapping variables to the page with the URI 'subdir/view' and any child pages: $pages['subdir/view$|subdir/views/:any'] = array('my_js' => 'my_js_value');
  • edited June 2011
    Thank you.

    The $pages solutions are worth my knowing about for the future, but they don't actually seem to solve my current issue -- the need to create the variable content using page specific information and the fact that that content is complex, and requires accessing a database table to create it.

    Unless there is some better way to do it, I created a $var['inline-js'] that is echoed in my header block (which is used by many pages). This javascript has to be between the head tags. I have $var['inline-js'] set up to be empty unless I happen to need to use it so that the js only gets created when I need it. I am putting all of the logic to create $var['inline-js'], including use of a model, into the _variables/view.php file.

    The need to get the javscript into the head and having to create it dynamically seemed to either fit either actually creating a page controller and building $var['inline-js'] there, building it in a rather massive script embedded in the top of my view.php file, or finding somewhere else that I could do it before the html page actually gets built. Other than the "one URI segment deep issue", the _variables/view.php file is letting me do it without having the top of the view.php file be cluttered with logic (I have a non-php html creator working with me, the closer the view.php file is to pure html the better).

    Unless there is some big flaw in this logic, I'm thinking that since there aren't too many of these pages, I just use the directory structure that works instead of trying to make that structure mimic my nav structure.
  • edited 4:08AM
    That should work too... and like you mentioned, you can always use a normal CI controller if you want to.
  • edited 4:08AM
    An asset for future release might be letting the _variables directory have subdirectories that track same-named subdirectories in the views directory.

    Thanks -- I'm enjoying working with the program
  • edited 4:08AM
    Noted.
Sign In or Register to comment.