Link to home
Start Free TrialLog in
Avatar of Desire2change
Desire2change

asked on

Reuse HTML code !!

I want to reuse an HTML template again and again just changing the field names , drop down options , image tags . Is it possible to do without recoding the HTML code . Please help me .
Avatar of h23
h23

Yes yo can but you must use a a server language like php or asp you can create a configuration file like this in php

config.php
<?
$title='This is the title of my page';
$field1Name='name';
$field1Class='myclass';
$field1Value='value';
$field2Name='lastname';
$field2Class='myclass';
$field3Name='age';
$field4Class='myclass';

$dropdown1Name='othername';
$dropdown1Option[0]='option1';
$dropdown1Option[1]='option2';
$dropdown1Option[2]='option3';

?>

then you main page could be like this:
main.php
<?
include('config.php');
echo "<html>";
echo "<head>$title</head>";
echo "<body>";
echo "<input type='text' name='$fieldName1' class='$field1Class' value='$field1Value'>";
echo "<input type='text' name='$fieldName2' class='$field2Class' value='$field2Value'>";
echo "<select name='$dropdown1Name'>";
foreach($ dropdown1Option as $key=>$value){
echo "<option value='$key'>$value</option>";
}
echo "</select>";

echo "</html>"
?>

and so on

?>
?>
Avatar of Desire2change

ASKER

Hi ,

        Is that HTML page can be generated afetr running this script ?


Regards
well. you can write the code, than open the php page, this will generate the html then you can view source of page and save the generated code
Can you please run it and show me in any server .

ASKER CERTIFIED SOLUTION
Avatar of h23
h23

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
With pure HTML and no serverside at all, you can use some JavaScript trick and cloneNode to paint the HTML pages. But be warned that it involved heavy DOM operations.
I suggest a split between the experts that participated.  Let me know if you would like me to provide specific comments.  I hope this helps and thanks for your time cleaning, etc.

bol