Welcome to Geeklog, Anonymous Sunday, May 19 2024 @ 02:30 am EDT

Geeklog Forums

Template Html


Anonymous

Anonymous
Hi, i was wondering if someone could shed some light for me on thtmls, and how they are used/work. I would more specifically like to know how they relate to php, and even more specifically how do forms work with them. I am used to templates being just a frame, to which you just add content... but i find it difficult to see how it can be a 2 way thing (form submission of all sorts) thanks guys, geeklog rocks!
 Quote

Status: offline

rawdata

Forum User
Full Member
Registered: 02/17/03
Posts: 236
A theme is one big html page (actually multiple html pages) that is chopped up into smaller pieces and placed inside different .thtml files. By doing this, you can write code to parse over a particular section of the site multiple times when building it. For example, there's one blockheader.thtml and one blockfooter.thtml file. If your site has say 10 blocks on a page, the code will parse 10 times over both of those files to build all the blocks. Templates are a method to keep web designers out of the code so they don't break it or get lost in it. Since many people are use to mixing code with html, it takes awhile to learn this concept. Since pages are broken up into multiple files, it takes designers awhile to visualize how all the pieces fit together to make up a page. As for creating a form, you can use the login form as a basic example to follow. The template for this is located in <path to your layout theme>/users/loginform.thtml. Inside that file, you will see html code with variable stubs inside curly brackets like this {start_block_loginagain}. Each one of those contains wording on your form. Inside your code, you would build what goes into those variable stubs. Using the login example again... First, you would build a template and then tell it where the .thtml file is located: $user_templates = new Template ($_CONF['path_layout'] . 'users'); $user_templates->set_file('login', 'loginform.thtml'); Then you set each variable to the name you want to appear in each of the stubs. By using language files as is done in Geeklog, your software can be easily translated so others who speak a different language can also use it. In this example, array $LANG04 in the language files is where the actual words appear. $user_templates->set_var('site_url', $_CONF['site_url']); $user_templates->set_var('start_block_loginagain', COM_startBlock($LANG04[65])); $user_templates->set_var('lang_message', $LANG04[66]); $user_templates->set_var('lang_username', $LANG04[2]); $user_templates->set_var('lang_password', $LANG04[4]); $user_templates->set_var('lang_forgetpassword', $LANG04[25]); $user_templates->set_var('lang_login', $LANG04[80]); $user_templates->set_var('end_block', COM_endBlock()); After setting each of the variables, you're now ready to output the form. First you parse the .thtml file to fill in all those stub variables you have the .thtml file. Then you spit out the html code into a variable (in this example's case $retval) for further processing. $user_templates->parse('output', 'login'); $retval .= $user_templates->finish($user_templates->get_var('output')); If you want the login code to appear on a page you do it with an echo. In this particular example, the login form is wrapped inside COM_startBlock() and COM_endBlock(). echo($retval); If you want the form wrapped inside a geeklog page, then you add the function calls COM_siteHeader() and COM_siteFooter() like this: $display = COM_siteHeader(); $display .= $retval; $display .= COM_siteFooter(); echo($display); To parse the template and to call any of GL functions, you need to add lib-common.php at the top of your code page like this: require_once('../lib-common.php'); //set this to the right path to the file If this is only for your site, you don't have to use templates or language files. You can place all the html for the form right inside your code if you want. It took me awhile to figure out how to use these templates. I kinda like them now and have used them on stuff unique to my site. The only thing I haven't used templates for are the contents inside blocks. I guess I should. Hope I didn't lose you.
 Quote

Anonymous

Anonymous
Thanks you VERY much!!!
 Quote

All times are EDT. The time is now 02:30 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content