Preserve Region with default content

Any template questions or comments or suggestions

Preserve Region with default content

Postby smj on Mon Jul 31, 2006 3:14 pm

Hi all,

is there a way to define a default content within a preserve region ?
Something like this:

Template:

<% output.preserveBegin \"IDS\" %>
int ID_AAA = TODO_ENTER_ID_HIER;
int ID_BBB = TODO_ENTER_ID_HIER;
<% output.preserveEnd \"IDS\" %>

Result file:

/*::PRESERVE_BEGIN IDS ::*/
int ID_AAA = TODO_ENTER_ID_HIER;
int ID_BBB = TODO_ENTER_ID_HIER;
/*::PRESERVE_BEGIN END ::*/

thx in advance,
juri
smj
Lurker
 
Posts: 1
Joined: Mon Jul 31, 2006 3:06 pm

Postby mike.griffin on Sun Aug 06, 2006 2:48 am

User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Preserve Region with default content

Postby mfreidge on Thu Feb 22, 2007 10:54 pm

Sorry, Mike.
I think, you misunderstood Juri's question.

The question was:
Is there a way to define a default content within a preserve region in TEMPLATE?

All generated files would have the default text within PRESERVE_BEGIN/PRESERVE_END block when the files will be generated
at the first time.

After this user can manually change the content of block only in some files.


I didn't find the answer in the referred post http://www.mygenerationsoftware.com/php ... .php?t=546
Michael Freidgeim
Blog: http://geekswithblogs.net/mnf/
mfreidge
Corporal
 
Posts: 16
Joined: Tue Aug 01, 2006 3:21 am

Postby justin.greenwood on Fri Feb 23, 2007 2:56 am

There is a way to do it.
Code: Select all
// getPreserveBlock returns the preserved data including the tags
var data = output.getPreserveBlock(key);

//You could use string functions here to add your default data if all you have is the start and end tags

output.write(data);

//-----------------------------------------------------

// getPreservedData returns the preserved data only
var data = output.getPreservedData(key);
%>
/*::PRESERVE_BEGIN IDS ::*/<%= data %>/*::PRESERVE_BEGIN IDS ::*/
<%


Play around with those functions and you'll probably find the solution you need
User avatar
justin.greenwood
Site Admin
 
Posts: 441
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Preserve Region Default value

Postby ati_ozgur on Wed Aug 15, 2007 9:12 am

My solution to this problem is below:

output.setPreserveSource(outputFullFileName, \"//::\", \":://\");

<%
try
{
output.getPreservedData(\"inheritance\");
output.preserve(\"inheritance\");
}
catch(NullReferenceException)
{
string preservedBlock = output.getPreserveBlock(\"inheritance\");
string newBlock = preservedBlock.Replace(\"////\",
\"// \" + Environment.NewLine
+ \": BaseTypeLibrary \" + Environment.NewLine + \"//\");
output.write(newBlock);
}

%>
ati_ozgur
Lurker
 
Posts: 6
Joined: Mon Jul 11, 2005 6:37 am


Return to General Template Questions/Comments

Who is online

Users browsing this forum: No registered users and 1 guest