CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 Can someone explain template blocks to me. (CCS)

Print topic Send  topic

Author Message
rbaldwin
Posted: 07/02/2002, 12:57 PM

Can someone explain template blocks to me. (CCS, and .asp)

I want to display a label {Country} on an Edit screen but on an Insert screen I want to display a listbox {CountryList_Options}

I'm trying to use HTMLTemplate.Parse (which has been suggested to me but i don't see HTMLTemplate in the HELP?)

I've been offered solutions in previous threads but i guess i haven't grasped the concept yet.

I have this template snippet:

<tr>
<td class="InLineFieldCaptionTD">Country </td>
<td class="InLineDataTD">
<!-- BEGIN Country -->
{Country}
<!-- END Country -->
<!-- BEGIN CountryList -->
<select name="CountryList">
<option value="" selected>Select Value</option>
{CountryList_Options}
</select>
<!-- END CountryList -->
</td>
</tr>

And i have this beforeshow event.

Function f_04AddlBankInf_BeforeShow() 'f_04AddlBankInf_BeforeShow @2-C91A7A72

'Custom Code @26-73254650
' -------------------------


if (f_04AddlBankInf.EditMode) then
Call WriteLogFile("editMode=" & f_04AddlBankInf.EditMode)
f_04AddlBankInf.Country.Value = CCDLookUp("Country", "00Country_BankData", "ID=" & CCToSQL(f_04AddlBankInf.Country.Value,"Integer"), DBConnection1)

HTMLTemplate.Parse "Country", true

else
HTMLTemplate.Parse "CountryList", true

End if


f_04AddlBankInf.modifyUser.Value = CCDLookUp("Login", "Users", "ID=" & _
CCToSQL(f_04AddlBankInf.modifyUser.Value,"Integer"), DBConnection1)
' -------------------------
'End Custom Code

End Function 'Close f_04AddlBankInf_BeforeShow @2-54C34B28
Chris K.
Posted: 07/02/2002, 3:28 PM

CodeCharge and CodeCharge Studio's HTML files are template files used by main page script (ASP/PHP/CFML etc) to retrieve fragments of HTML code. Those fragments are either passed to page output without modifications or filled with data to obtain dynamic content. All those fragments are composing final page output.

As it was said previously some HTML template fragments are used to fill with data by page script. These are template blocks and template variables.

Template variables look like {template_var} in the template (where template_var is the name of particular variable). They are containers for some values assigned in the script. The values can be assigned by generated code (assigning database values to fields, labels textboxes), or manually by user in events with some customized content (using setvar/set_var method/function).

Another piece of HTML template is template block. This is HTML region marked under some name for script processing. The blocks are created using HTML comments with predefined syntax.

in CodeCharge:
<!--BeginBlockName-->Block content<!--EndBlockName-->

in CodeCharge Studio
<!--BEGIN BlockName-->Block content<!--END BlockName-->

The comments have constant prefixes, BlockName is the name of particular template block, Block content is HTML code possibly with nested blocks and template variables. Template blocks are used to identify template regions as forms, grids, its headers and footers, repeatable rows or any other custom regions.

Template blocks can be parsed by page script. Parsing involves assigning all template variables that were assigned values (replacing those {template_var} with values assigned to template_var template variable) and inserting already parsed nested template blocks. After parsing, filled template block is placed in the final page output or saved for including during parent block parsing.

Parsing can be accumulative. This means that after block parsing, resulting code is appended to previously parsed content from this block. Unparsed template block is preserved for further accumulative parsing. This method is used for repeatable content like grid rows. Each row from database is iterated, row template block is retrieved, assigned values and parsed accumulative (appended to previous rows).

Template blocks can reset (hidden) by assigning empty string to their parsed content (using setvar/set_var method/function). This can be used to create hiddable content, when some region has been enclosed with template block delimiters.

You can find nearly the same article at:
http://www.gotocode.com/art.asp?art_id=91&
Chris K.
Posted: 07/02/2002, 3:35 PM

Another comment is that blocks that are not parsed are not shown in the resulting page. If you create custom block enclosing some controls it won't be show by default (as the code to parse it hasn't been generated). Parsing isn't recursive, so when parsing some block, nested ones aren't parsed.

To show custom block (according to selection) you have to parse it. You do it in your event. The controls will shown, but not assigned values. That is because this event is called before template variables are assigned in control's Show methods. So when you parse some block in BeforeShow event, later control's assignments doesn't affect block as it has been already parsed.

To eliminate this you should first show the control you want to display (using its Show method (template variables will be assigned) and then parse enclosing block to make it visible.

Your event should look like:

Function f_04AddlBankInf_BeforeShow() 'f_04AddlBankInf_BeforeShow @2-C91A7A72

'Custom Code @26-73254650
' -------------------------


if (f_04AddlBankInf.EditMode) then
Call WriteLogFile("editMode=" & f_04AddlBankInf.EditMode)
f_04AddlBankInf.Country.Value = CCDLookUp("Country", "00Country_BankData", "ID=" & CCToSQL(f_04AddlBankInf.Country.Value,"Integer"), DBConnection1)

f_04AddlBankInf.Country.Show Tpl
HTMLTemplate.Parse "Country", true

else

f_04AddlBankInf.CountryList.Show Tpl
HTMLTemplate.Parse "CountryList", true

End if


f_04AddlBankInf.modifyUser.Value = CCDLookUp("Login", "Users", "ID=" & _
CCToSQL(f_04AddlBankInf.modifyUser.Value,"Integer"), DBConnection1)
' -------------------------
'End Custom Code

End Function 'Close f_04AddlBankInf_BeforeShow @2-54C34B28
Nicole
Posted: 07/03/2002, 5:41 AM

Hello,
to show/hide controls (parts of html code) please follow the steps:
1. surround part of the html code with html comments as you did, e.g.:
<!-- BEGIN CountryList -->
<select name="CountryList">
<option value="" selected>Select Value</option>
{CountryList_Options}
</select>
<!-- END CountryList -->

2. create form Before Show event like:
if (condition_to_hide)
EventCaller.CountryList.Visible = False
end if


Once you added custom template variable to the form, e.g.:
{hello}
to assign it custom value use the following code in Form Before Show event:
EventCaller.TemplateBlock.Variable("hello") = "custom value"
rbaldwin
Posted: 07/03/2002, 6:34 AM

Thanks Chris for taking the time to provide such a detailed explanation. It all makes sense. However your solution isn't working for me. In both the true and false cases (of editmode) both of my form elements (label and listbox) are showing.

But thanks to Helen D. from support the answer to my problem is this (and elegent in its simplicity).

In CCS to show/hide controls (parts of html code) please follow the steps:
1. surround part of the html code with html comments as you did, e.g.:
<!-- BEGIN CountryList -->
<select name="CountryList">
<option value="" selected>Select Value</option>
{CountryList_Options}
</select>
<!-- END CountryList -->

2. create form Before Show event like:
if (condition_to_hide)
EventCaller.CountryList.Visible = False
end if

chaskunz
Posted: 07/10/2002, 5:02 PM

Following the instructions directly above:

CCS - basically standard grid - around Add New link at bottom of page next to Navigator I have added block ShowAddNew and end block:

<!-- END NoRecords -->
<tr>
<td colspan="8" nowrap class="MultipadsFooterTD">
<!-- BEGIN ShowAddNew --><a href="{person_insert_Src}">Add New</a>  
<!-- END ShowAddNew -->
<!-- BEGIN Navigator Navigator -->

In Before Show custom code for grid I have entered:

function person_BeforeShow() { //person_BeforeShow @5-E7C5DAF9

//Custom Code @289-2A29BDB7
// -------------------------
global $person;
global $DBConnection1;
$current_user = CCGetUserID();
echo "Current User = $current_user<br>";
$cur_user_gp = CCDLookUp("group_id","user","user_id=".
$DBConnection1->ToSQL($current_user,ccsInteger),$DBConnection1);
echo "Current User Group = $cur_user_gp<br>";
if(!$current_user || $cur_user_gp < 2){
$person->ShowAddNew->Visible = false;
}
// -------------------------
//End Custom Code

} //Close person_BeforeShow @5-FCB6E20C

The block NEVER shows no matter what, now that I have the block around the html, even if I delete the custom code. What else do I have to do?

Nicole
Posted: 07/11/2002, 4:14 AM

Hello,
Here is solution for PHP:
1. surround link with html comments:
<!-- BEGIN AN -->
<td class="AquaFooterTD" nowrap colspan="2"><a class="AquaDataLink" href="{events_Insert_Src}">Add New</a> 
<!-- END AN -->

Once it is done the link won’t be displayed on the form without following step

2.create form Before Show event to display link:
global $Tpl;
$Tpl->Parse("AN", false);
Jeroen
Posted: 07/18/2002, 4:04 PM

I've created a template block and I've parsed it. I can see the block now, but all the {variables} aren't shown. Why is this?
Nicole
Posted: 07/22/2002, 5:54 AM

Hello,
to show/hide controls like table row with the table field (e.g., textbox, listbox or any other) in PHP surround the html code with html comments the same way as described in my response for ASP and create form Before Show event like:
global $<form_name>;
$<form_name>-><field_name>->Show();
global $Tpl;
$Tpl->Parse("products", false);
where "products" is html comment:
<!-- BEGIN products -->
<!-- END products -->

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.