Archived Thread: 'Templates - Insider Secret Tips!'
-
Templates - Insider Secret Tips!Posted by michaelthompson on Thursday, June 14, 2007
Hello,
I find subsonic to be a great tool. Just what I've been looking for... I think.
I may have a great misunderstanding, but I thought you could create your own templates ultimately to generate my own custom output classes/pages/etc.
I'm creating a web application and would like to use subsonic to generate the CRUD files with a bit of my flavor added to the mix (templates).
I've found several post stating to place "templateDirectory="[FULL_PATH]" in the <section name="SubSonicService" ..... /> of the web.config file. No Success :(
I've even tried placing the attribute in the sonic.exe.config file, and 'lo and behold' I get the same error stating "Unrecognized attribute 'templateDirectory'. Note that attribute names are case-sensitive." What the ....
Can someone shed a bright light on what my perception of this awesome tools limitations are. Is this tool not capable of doing this. If so, can someone please give me a great example of how this is done. I would really appreciate it... you would not believe how much. (Step by step would be way cool)
The reason for wanting to generate my own templates is to be able to utilizes subsonic's data manipulation power to use with Visual WebGUI. * see http://www.visualwebgui.comThanks in advance
-
Re: Templates - Insider Secret Tips!Posted by canofunk on Thursday, June 14, 2007
You were very close, but I believe you placed the value in the wrong place. [:)]
The templateDirectory attribute belongs in the SubSonicService section, not in the configSection entry. For example:
<SubSonicService defaultProvider="Northwind" templateDirectory="c:\mytemplates">
<providers>
<clear/>
<add name="Northwind" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="Northwind" generatedNamespace="Northwind"/>
</providers>
</SubSonicService> -
Re: Templates - Insider Secret Tips!Posted by michaelthompson on Thursday, June 14, 2007
Thanks!
Forgot to ask.... Is it possible to do the same for the "Batch Scaffold Generator". I've just noticed that while in a web project, there is no way to generate the web pages, so I'm resorting to the "Batch Scaffold Generator" (which is part of the SubSonicCentral web app).
I'm changing the templates, but I only get boiler plate generation (it does not use my template) when using the SubSonicCentral.I've setup everything in my web application as noted in the video, and it now uses my templates for the classes. But no go for web page generation (scaffold)
What do you suggest.
Thanks in advance.
-
Re: Templates - Insider Secret Tips!Posted by canofunk on Thursday, June 14, 2007
So the classes generate with your customizations, but the scaffolds do not?
The Scaffolds should be subject to the same rules as the classes, and will refer to the templates as long as the path templateDirectory path setting is correct, and the name of your modified template exactly matches the original. If it cannot locate the template at the specified location, it will fall back to the default template.
-
Re: Templates - Insider Secret Tips!Posted by michaelthompson on Thursday, June 14, 2007
I think I see the issue.
I've noticed in SubSonic 2.0.1\Source\CodeGeneration\CodeService.cs:
//decide where to pull the text from
if (!String.IsNullOrEmpty(templateDirectory)) {
template += FileExtension.DOT_ASPX; <----------------------------------------------------------------Line 417 -- The template already has the .aspx ext. it's being doubled here. So when the condition "File.Exists()", it appears as "CS_[TemplateName].aspx.aspx", thus resulting to the boiler plate templateI think this is the problem.... Your thoughts?
Utility.WriteTrace("Looking for template "+template+" in "+templateDirectory);
//make sure the template exists
templatePath = Path.Combine(templateDirectory, template);
if (File.Exists(templatePath)) {
//pull the text from there
templateText = SubSonic.Utilities.Utility.GetFileText(templatePath);
} else {
//empty out the template so we can pull from the Resources
templateText = string.Empty;
Utility.WriteTrace("Template " + template+" NOT FOUND in directory "+templateDirectory+"; using RESOURCES");
}
-
Re: Templates - Insider Secret Tips!Posted by canofunk on Thursday, June 14, 2007
Crud... I didn't think that bug was in the actual release 2.0.1. It's been fixed for the upcoming 2.0.2 (along with overall improvements to that whole method).
For a quick fix, just replace the following three consts SubSonic,TemplateName:
public const string DYNAMIC_SCAFFOLD = "DynamicScaffold.aspx";
public const string GENERATED_SCAFFOLD_MARKUP = "GeneratedScaffoldMarkup.aspx";
public const string GENERATED_SCAFFOLD_CODE_BEHIND = "GeneratedScaffoldCodeBehind.aspx";with
public const string DYNAMIC_SCAFFOLD = "DynamicScaffold";
public const string GENERATED_SCAFFOLD_MARKUP = "GeneratedScaffoldMarkup";
public const string GENERATED_SCAFFOLD_CODE_BEHIND = "GeneratedScaffoldCodeBehind";
-
Re: Templates - Insider Secret Tips!Posted by michaelthompson on Thursday, June 14, 2007
Thanks...
I hacked already...the lazy way (quick and dirty as we say in the ATL)template = template.Replace(".aspx",""); //added line above original line # 417
Looking forward to the next release....
Very nice response times... You guys are dedicated.. I like it!