Skip to main content
Inspiring
November 14, 2010
Question

Controlling output's tab indenting

  • November 14, 2010
  • 1 reply
  • 1566 views

As a stickler for code semantics, I've noticed that my generated code will use indenting in my .cfm file, but if that .cfm file calls, say, a function from another file, and in the called .cfm file it has indenting to keep that file's output looking good, that when it gets pulled into the caller's output, the indenting becomes increased.

Has anyone come across a method to uniform this?

    This topic has been closed for replies.

    1 reply

    Inspiring
    November 14, 2010

    Always specify output=false on your functions.  Switch the "control whitepsace" (or whatever it is) setting on in CF Admin.  Use CFScript as much as possible as it doesn't generate any output at all (unless, like, with a writeOutput() statement ;-).

    --

    Adam

    Inspiring
    November 14, 2010

    <cffunction name="generateCode" access="public" output="false" returntype="string">

    <!--- Define params. --->

    <cfparam name="strOut" default="" type="string" />

    <cfsavecontent variable="strOut">

    <cfoutput>

    <div>this div gets tabbed</div>

    </cfoutput>

    </cfsavecontent>

    <!--- Return. --->

    <cfreturn strOut />

    </cffunction>

    The above function is instantiated into application.comUDF so I call it like:

    #application.comUDF.generateCode()#

    (I've determined that I cannot call it via CFINVOKE, which would have been nicer.  The following won't output the returned code)

    <cfinvoke component="#application.comUDF#" method="generateCode" returnvariable="strOut" />

    (without having to then dump strOut to the buffer)

    In the function, if I add more tabs they are carried over, so I could just tab that code a lot until it lines up in the generated page code, but this seems as a roundabout solution.

    Inspiring
    November 14, 2010

    Are you referring to indentation in the generated html code?

    <cfparam name="strOut" default="" type="string" />

    I do not know what else your function is doing. But the use of cfparam in an application scoped function jumped out at me. Is strOut supposed to be a function local variable?