ths ones kinda scary to explain.. so I'll explain WHY I have to do this.. perhaps my approach is wrong, and someone can recommend a better way to do it...
since my eggie actually generates specific and dynamic elements of my website, I came up with an idea to use TEMPLATE files instead of just writing mean code into the tcl scripts.. which would mean having to REWRITE the script over and over each time a change to the website was needed...
I had inital code that took a webpage.tpl file and ran it through some filters to replace given varables with the actual assigned values when needed.. For efficiency, the script worked in modes..
first mode: SetVars
here we load the template fille into a varable ONLY ONCE at startup...
Code: Select all
proc setvars {} {
global MyTPL TmpIDX
if {([file exists "$MyTPL/index.tpl"])} {
set TmpIDX "[read [open "$MyTPL/index.tpl" r]]";
};
};
Second Mode: Output
Code: Select all
proc Output {} {
global TmpIDX MyWeb DetIA DetSA;
if {$Csh01 != "$DetIA $DetSA"} {
set Csh01 "$DetIA $DetSA";
regsub -all -- "\\\$DetIA" $TmpIDX "$DetIA" MetaIDX;
regsub -all -- "\\\$DetSA" $MetaIDX "$DetSA" MetaIDX;
set Out [open "$MyWeb/index.html" w]; puts $Out "$MetaIDX";
flush $Out;
close $Out;
};
};
that, in itself makes it rather MEANINGLESS to do in the first place!
So, I started out with a new approach.. to read a directory and generate a list of .tpl files in said dir...
Code: Select all
foreach VarA [read [open $MyTPL r]] {
if {(([string first ".tpl" $VarA]) >= "1")} {
set VarB [read [open "$MyTPL/$VarA" r]];
set VarA [string map {".tpl" ""} $VarA];
global [read $VarA];
set [read $VarA] $VarB;
};
};
Then, in Output..
Code: Select all
foreach VarA [read [open $MyTPL r]] {
if {(([string first ".tpl" $VarA]) >= "1")} {
set VarA [string map {".tpl" ""} $VarA];
global $VarA;
set $VarA [read [open $VarA r]];
regsub -all -- "\\\$DetIA" $VarA "$DetIA" MetaIDX;
regsub -all -- "\\\$DetSA" $MetaIDX "$DetSA" MetaIDX;
set Out [open "$MyWeb/$VarA.html" w];
puts $Out "$MetaIDX";
flush $Out;
close $Out;
};
};
THIS DOESN'T WORK!
appariently, i can not assign a string from one varable as the name of another..and THEN make it global!
this is where I'm stuck!
-DjZ

