7 Replies Latest reply on Dec 20, 2010 10:36 AM by Dan Bracuk

    Changing The Value of the CF Relative Path

    i69alot Level 1

      Hi:

       

      Is there a way to change the value of the relative path CF uses when resolving the template attribute of cfinclude? In particular, I'd like to be able to assign the relative path of the calling template of a custom tag to the relative path of the custom tag itself, regardless of where the tag resides. Suggestions welcome. Thanks!

        • 1. Re: Changing The Value of the CF Relative Path
          Adam Cameron. Level 5

          Well: no.  By definition a "relative path" is... well... relative!  IE: relative to where it is being used.

           

          So what you want is just "some path" not a "relative path".

           

          The only way I can think to effect what you want is to pass in a "contextPath" attribute, or something.

           

          Or you could possibly mess around with an Exception object which will have its tag context returned, which should return the path the the file calling the custom tag in the... second (?)... position in the array (the first position being the current file), I guess.  But then you'd have a full file system path, which is no good for a <cfinclude>.

           

          What exactly are you trying to implement here?

           

          --

          Adam

          • 2. Re: Changing The Value of the CF Relative Path
            Dan Bracuk Level 5

            For custom tags, you can specify a directory for their home on your admin page.  If you are going to be using shared hosting, I'm not sure, but I think you can specify a home in your Application.cfc.  If your custom tag has to send data back, the caller scope is what you want.

             

            Cfinclude has nothing to do with custom tags.

             

            As Adam asked, "What are you trying to accomplish?"

            • 3. Re: Changing The Value of the CF Relative Path
              i69alot Level 1

              Thanks for your reply.

               

              I'm lazy.

               

              I'd like to use <cfinclude template="cf_template_only_no_folder_info.cfm" />, no matter where I'm calling a template from, no matter how many folders deep. This bears the striking resemblance of what a custom tag does, expect the scoping is different, among other things.

               

              You're right, I just need some path, not the relative path. I should also mention that all my templates are within a top level app folder or lower.

               

              Since I first posted this, I've come up with a possible solution, but would still like to hear other ideas. Your opinion is welcome. Here it is...

               

               

              1) Create a custom tag called inc.cfm. Basic syntax would be <cf_inc template="cf_template_only_no_folder_info" />

               

              2) Code the tag as follows:

               

              <!--- Set the template attribute aside --->

              <cfset request.template = variables.attributes.template />

               

              <!--- "Re-scope" the caller variables --->

              <cfset variables = StructCopy(caller.variables) />

               

              <!--- Put the template attribute value back in the custom tag scope --->

              <cfset variables.template = request.template />

               

              <!--- Now include the template attribute --->

              <cfinclude template="#variables.approot#/#variables.template#.cfm" />

               

              I haven't tried this yet, but this or a close version of it should be able to get the job done. Calls to inc.cfm from within inc.cfm itself (via cfinclude) should be accommodated.

               

              What do you think?

              • 4. Re: Changing The Value of the CF Relative Path
                Dan Bracuk Level 5

                Just out of curiousity, do you have any other types of re-useable files like javascript or images?  If so, the way you handle those might work for included .cfm files.

                • 5. Re: Changing The Value of the CF Relative Path
                  Owain North Level 4

                  Can you not use an application-level mapping? Or any other app-level variable?

                   

                  Or am I still missing the point of what you're trying to achieve?

                  • 6. Re: Changing The Value of the CF Relative Path
                    Adam Cameron. Level 5

                    What do you think?

                     

                    Bleah is what I think.

                     

                    And you see this as better than sticking a path into your <cfinclude> calls?

                     

                    [boggle]

                     

                    <cfinclude template="#variables.approot#/#variables.template#.cfm" />

                     

                     

                    This would require all the include files to be stored "flat", in the approot dir?  Is that what you want to do?  In that case, why not just stick 'em all in an /includes/ dir, and hard-code that:

                     

                    <cfinclude template="/includes/#variables.template#.cfm">

                     

                    --

                    Adam

                    • 7. Re: Changing The Value of the CF Relative Path
                      Dan Bracuk Level 5

                      This is the approach we use for images, stylesheets, javascript, User Defined Functions, and some Includes (headers and footers mainly).