<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"Lucida Console";
        panose-1:2 11 6 9 4 5 4 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Plain Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.PlainTextChar
        {mso-style-name:"Plain Text Char";
        mso-style-priority:99;
        mso-style-link:"Plain Text";
        font-family:"Calibri",sans-serif;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoPlainText">Need the mapfile equivalent of SASS... A standard, platform-independent pre-processor would be nice. I’ve heard of folks using the C pre-processor to do this sort of thing so they’d have a version of a mapfile (and no includes) full
 of #define and #ifdef structures. In some cases I’ve gone nuts with includes and then used a super simple MapScript script that reads and then immediately saves things to an optimized (sort of compiled) version with no includes.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Something like variables (and maybe functions) could potentially be built into mapfile processing itself. I could see  (for example) setting a block like so at the mapfile level:<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">VARIABLES<o:p></o:p></p>
<p class="MsoPlainText">  ‘key1’ ‘value1’<o:p></o:p></p>
<p class="MsoPlainText">  ‘key2’ ‘value2’<o:p></o:p></p>
<p class="MsoPlainText">  …<o:p></o:p></p>
<p class="MsoPlainText">END<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">And then setting a mechanism to reference them as the file is processed (COLOR {key1}). The nice thing about this approach is that includes would take their cue from the parent mapfile and could behave differently for different parents.
 That would be great for doing something like map themes. Just thinking out loud.
<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Steve<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> mapserver-users [mailto:mapserver-users-bounces@lists.osgeo.org]
<b>On Behalf Of </b>lars.schylberg@blixtmail.se<br>
<b>Sent:</b> Friday, October 13, 2017 6:41 AM<br>
<b>To:</b> mapserver-users@lists.osgeo.org; Jörg Thomsen (WhereGroup) <joerg.thomsen@wheregroup.com><br>
<b>Subject:</b> Re: [mapserver-users] passing variables to includes<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p style="margin:0in;margin-bottom:.0001pt">Hi Jörg,<br>
<br>
I also had this same thought and it would be a good mechanism.<br>
But I solved it with my own preprocessing.<br>
<br>
I have been doing Nautical charts with Mapserver for a<br>
couple of years and realized that I was reusing<br>
the same layers up to 18 times. <br>
<br>
So I did templates where I had LAYER->NAME, LAYER->GROUP,<br>
LAYER->DATA and STYLE->COLOR as variables in Mapserver templates. <br>
Color for instance has fixed names like "DEPVS",<br>
that means depth very shallow. <br>
But depending on if it is day mode, dawn dusk mode or night mode<br>
the colors have different rgb or hex values. <br>
All variables are stored in csv files.  The variables are read into<br>
associative arrays in a bash script.  Then  I use my Mapserver<br>
mapfile templates that are processed with a very long sed statement<br>
that substitutes the variables depending on color mode and scale level.  <br>
<br>
Layer names and groups have one csv file that tells how to<br>
assemble all the layers.  To make it even more flexible, I can<br>
also use offical IHO colors, Swedish or French color tables<br>
to get different look and feel.<br>
<br>
An example is for instance the layer template for rivers:<br>
<br>
#### Rivers Lines ####<br>
<br>
LAYER<br>
    NAME  "Rivers_line_{CL}"<br>
    GROUP "{GROUP}"<br>
    METADATA<br>
        "ows_title"   "Rivers"<br>
        "ows_enable_request"   "*"<br>
        "gml_include_items" "all"<br>
        "wms_feature_mime_type" "text/html"<br>
    END<br>
    TEMPLATE blank.html<br>
    TYPE LINE<br>
    STATUS ON<br>
    MAXSCALEDENOM {MAXSCALE}<br>
    DATA "{PATH}"<br>
    CLASS<br>
        NAME "Rivers (lines)"<br>
        STYLE<br>
           # DEPVS<br>
           # RGB # COLOR {DEPVS_rgb}<br>
           COLOR "{DEPVS}"<br>
           WIDTH 1.5<br>
           # RGB # COLOR {OUTLL_rgb}<br>
           OUTLINECOLOR "{OUTLL}"<br>
           OUTLINEWIDTH 0.3<br>
        END<br>
    END<br>
END<br>
<br>
<br>
All this can be seen in the git hub:  <a href="https://github.com/LarsSchy/SMAC-M">
https://github.com/LarsSchy/SMAC-M</a><br>
I finally got permission from my company to release it this summer, so that we can discuss this.<br>
I would like to do a demo site with open data, but haven't had time to do this yet.<br>
<br>
The script: process_layer_color.sh shows the real processing part and the sed script.<br>
<br>
<a href="https://github.com/LarsSchy/SMAC-M/blob/master/chart-installation/generate_map_files/scripts/process_layer_colors.sh">https://github.com/LarsSchy/SMAC-M/blob/master/chart-installation/generate_map_files/scripts/process_layer_colors.sh</a><br>
<br>
Have fun<br>
<br>
Lars Schylberg<br>
Saab AB<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Lucida Console"">-----Originalmeddelande-----<br>
> Från: "Jörg Thomsen (WhereGroup)" <<a href="mailto:joerg.thomsen@wheregroup.com">joerg.thomsen@wheregroup.com</a>><br>
> Till: <a href="mailto:mapserver-users@lists.osgeo.org">mapserver-users@lists.osgeo.org</a><br>
> Datum: 2017-10-13 09:43<br>
> Ämne: [mapserver-users] passing variables to includes<br>
><br>
> Hi,<br>
><br>
> I had a MapServer Training this week and one of the participations asks<br>
> a nice question:<br>
><br>
> Is it possible to pass variables to includes? I think this is a very<br>
> good idea, it could save a lot of includefiles. In know it's very close<br>
> to mapscript, but has anyone done this without?<br>
><o:p></o:p></span></p>
</div>
</div>
</div>
</body>
</html>