DebugMode for Published Templates using Configuration Directives

| No Comments

With large volumes of code… sometimes it’s useful to place comments in the code to document what the code does.

In html, developers often use a html comment on a closing div tag to note which tag is being closed.

<div id="main-content">
    ...many lines of code here...
</div><!-- end of #main-content -->

Once the page is being published in the production environment, these comments are no longer necessary and just add to the weight of the file.

There are many ways to condition these links in Movable Type:

  • Create a Global Config template module and then set a variable in that template. Include this template module in all your templates and use the value to condition code.

    Global Config (use a value of 1 to show, 0 to hide)

    <mt:Var name="display_coments" value="0">

    Index Template

    <$mt:Include module="Global Config"$>
    <div id="main-content">
        ...many lines of code here...
    <mt:If name="display_commnts">
        <!-- end of #main-content -->
  • Use configuration directives in your template. There are a bunch of useful Configuration Directives for Movable Type. Use the value of config directives in your templates as conditionals.

    In the mt-config.cgi file add config directives:

    # Config Directives
    ## Required
    CGIPath /cgi-bin/branch-hanson/
    Database mt_db
    DBUser foo
    DBPassword bar
    DBHost localhost
    ## Optional
    DebugMode 1  # See
    FooBar 3     # Made up config directive

    Use the DebugMode config directive:

    <mt:If name="config.DebugMode">
        <!-- comment here -->

    Or make up your own and use the value such as FooBar:

    <mt:If name="config.FooBar" eq="1">
        <!-- condition 1 comment here -->
    <mt:If name="config.FooBar" eq="2">
        <!-- condition 2 comment here -->
        <!-- condition <$mt:Var name="config.FooBar"$> comment here -->

Hope either of these may be useful.

Leave a comment