By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,241 Members | 733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,241 IT Pros & Developers. It's quick & easy.

Setting up templates

P: 9
I am working on a project where the client wants to have multiple templates that customers can choose from for their site. We want everything automated. We are going to host the site for the customer. Any ideas of how to set this up? I am familiar with java, jsp, java servlets, html, and a little php.
May 15 '09 #1
Share this Question
Share on Google+
15 Replies


prabirchoudhury
100+
P: 162
hey..could you explain bit details abt how and what template you wnat to setup...
May 17 '09 #2

P: 9
The templates will be basically empty web site shells. The customer will choose one of the templates they like, and that will become their web site. The templates will be written in html for the most part, perhaps containing some jsp. We will be using a MySQL database to hold the options of the customer, i.e. which template, which color choices, what text do they want displayed in text field one for example.
May 20 '09 #3

Frinavale
Expert Mod 5K+
P: 9,731
Most of your work is going to have to be done in the Server Side code.

You're going to have to write a template HTML page that will be rendered.

Then you'll have to dynamically generate the styles for this page based on the user's selections. It'd probably be easiest to store the CSS code in your database ...but it's up to you how you implement it.

You will also have to dynamically grab the text content for the web pages from your database as well.
May 26 '09 #4

P: 9
Would you just put the CSS code into say a text data type in the database? I was thinking using jsp calls to the database to redirect to a specific folder that would contain the web site, style sheet, jsp pages ... and have each template in its own folder. Is this more cumbersomethan just using the css?
May 27 '09 #5

Frinavale
Expert Mod 5K+
P: 9,731
I don't know much about JSP but from what I do know is that you pretty much write the HTML structure for the page....in specific places in the page you're going to have JSP code (that is executed on the server) which will write dynamic content into the page.

So first you have to have some sort of HTML structure (template) that will generally lay out the page. Once you have this structure in place you can dynamically write the CSS and the content (text) into the page.

So, for example, this would be your HTML structure and anywhere that I have comments you'll have to replace with JSP code that does what I've specified in the comments:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2.    "http://www.w3.org/TR/html4/strict.dtd">
  3. <html>
  4. <head>
  5.   <title>
  6.     <!-- Dynamically grab the title for the page -->
  7.   </title>
  8.  
  9.  <style type="text/css">
  10.     body{
  11.       //here you need to dynamically 
  12.       //grab the style for the body of the
  13.       //web site...
  14.      }
  15.     .banner{
  16.       //here you need to dynamically
  17.       //grab the style used for the Banner
  18.       //displayed for the web page
  19.     }
  20.     .contentSection{
  21.       //here you need to dynamically
  22.       //grab the style used for the content (the text)
  23.       //displayed for the web page
  24.     }
  25.   </style>
  26. </head>
  27. <body>
  28.   <div id="bannerSection" class="banner">
  29.     <!---
  30.       Here you will dynamically display a Banner
  31.       It could be an Image, it could be some Text...
  32.       It could be whatever you want.
  33.  
  34.       Note the "class" property in the <div> for this section.
  35.       This class will be linked up to the style which is used
  36.       to style this section...the style is dynamically
  37.       generated but because the class name is known 
  38.       it'll work.
  39.      -->
  40.   </div>
  41.   <div id="contentSection" class="content">
  42.     <!---
  43.       Here you will dynamically display the content
  44.       (the text) for the web page..
  45.  
  46.       Note the "class" property in the <div> for this section.
  47.       This class will be linked up to the style which is used
  48.       to style this section...the style is dynamically
  49.      generated but because the class name is known 
  50.      it'll work.
  51.      -->
  52.   </div>
  53. </body>
  54. </html>
The CSS can drastically change how the layout of the page is displayed but it doesn't actually change the HTML structure of the page.

For example you could write CSS for the banner section that displays the banner above the page's content. Or you could write CSS that displays the banner section to the right or the left of the content.

CSS is very powerful and can drastically change how websites look to the end user even though the HTML structure of the page is the same as another page.
May 27 '09 #6

P: 9
That makes sense. I have done all the dynamic work with the html code using jsp and php, does it work the same way in the style sheet?
May 27 '09 #7

Frinavale
Expert Mod 5K+
P: 9,731
Wait a sec, are you creating external style sheets?
May 27 '09 #8

Dormilich
Expert Mod 5K+
P: 8,639
@borrisjd
it is possible to build CSS files through PHP (and I think JSP too), you only need to make sure the files are recognised as CSS by sending the appropriate headers.
May 27 '09 #9

P: 9
I am fairly new to html and css. I thought the css were always external. I guess by your question they are not. So if I put the css inside of my html page I can use jsp to call to the database like I have done before. If I were to use external is it possible to make that dynamic as well?
May 27 '09 #10

Dormilich
Expert Mod 5K+
P: 8,639
@borrisjd
not necessarily, but it makes maintenance much easier.

@borrisjd
yepp, there's not much difference.
May 27 '09 #11

P: 9
Very cool. Thanks for helping. I think I have enough to get started. I'm sure I'll be back when I get stuck lol.
May 27 '09 #12

Frinavale
Expert Mod 5K+
P: 9,731
Actually it's probably cleaner to keep them as external style sheets.

In this case all you have to do is write a JSP page that returns a Style Sheet instead of HTML.

This JSP page (I'm going to call it "JspPageThatDynamicallySpitsOutStyleSheets") would look something like:
Expand|Select|Wrap|Line Numbers
  1.     body{
  2.       //here you need to dynamically 
  3.       //grab the style for the body of the
  4.       //web site...
  5.      }
  6.     .banner{
  7.       //here you need to dynamically
  8.       //grab the style used for the Banner
  9.       //displayed for the web page
  10.     }
  11.     .contentSection{
  12.       //here you need to dynamically
  13.       //grab the style used for the content (the text)
  14.       //displayed for the web page
  15.    }
The JSP page that will display the website (the HTML) will request the external style sheet from the JspPageThatDynamicallySpitsOutStyleSheets like so:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2.    "http://www.w3.org/TR/html4/strict.dtd">
  3. <html>
  4. <head>
  5.   <title>
  6.     <!-- Dynamically grab the title for the page -->
  7.   </title>
  8. <link type="text/css" rel="stylesheet" href="/JspPageThatDynamicallySpitsOutStyleSheets.jsp?styleID=xyz"></link>
  9. </head>
  10. <body>
  11. <!-- .....-->
  12. </body>
Note the link.
It's making a request to the JspPageThatDynamicallySpitsOutStyleSheets, passing it a style ID as a parameter. The JspPageThatDynamicallySpitsOutStyleSheets will use the style ID to dynamically create the style sheet requested.
May 27 '09 #13

Frinavale
Expert Mod 5K+
P: 9,731
@Dormilich
@borrisjd
Hehe Dormilich you're too fast :)
(or maybe I'm just too slow)
May 27 '09 #14

Dormilich
Expert Mod 5K+
P: 8,639
It's always a good idea to send the appropriate headers along with the document
Expand|Select|Wrap|Line Numbers
  1. // PHP
  2. <?php
  3. header("content-type: text/css");
  4. ?>
  5.  
  6. // style sheet content here
there should be some adequate code in JSP
May 27 '09 #15

Dormilich
Expert Mod 5K+
P: 8,639
@Frinavale
murphy's law (more or less). if you're approaching the end, the effort will increase. it's 70 vs 27.
May 27 '09 #16

Post your reply

Sign in to post your reply or Sign up for a free account.