Jump to content

Smarty Confusion!*!*^


herghost

Recommended Posts

Firstly, I hope this is the right thread for this post:

 

I have recently started playing around with smart php template system, and have decided to try designing an application with it, I have read through the smarty site and various ebooks about smarty but one thing is confusing me

 

Say I have my main page, then to the left of that I have a side bar.

 

1, Would I create this in my .css?

2, Could I then add PHP blocks to this (ie, a latest news block, a login block etc)

3, How would I create these blocks in smarty?

 

I reliase this is a bit of a beginers question, but I just cant seem to find the answers I need! If anyone could point me in the right direction or explain that would be great.

 

My other question is, does the term smarty block refer to what I see as a block? ie a block of code that has a specific function, like a login box?

 

Many thanks from a very confused person!

Link to comment
Share on other sites

#this is the tpl file

 

assign data from php to this smarty variables

 

$smarty->assign('header',"some data or fetch a another template here ");

=========

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title></title>

    </head>

    <body>

<div id= "header"> {$header}</div>

<div id= "left">{$left}</div>

<div id= "right">{$right}</div>

<div id= "content">{$content}</div>

<div id= "footer">$footer</div>

</body>

</html>

Link to comment
Share on other sites

Hai,

First create a html file dont think about the smarty and once you got the frame , replace the content like in the revious example with smarty template variables {$content} then form php file you can send any data to this {$content}, that can be another login page , or registration page or some content.

 

 

Link to comment
Share on other sites

Thanks for your reply :)

 

Looking at your example am I right in saying that I create the <div> blocks in my css, and the code below is an example of assigning a php block to them? Ie <div id= "left">{$left}</div>, if I then create a php latest news block and call it $left it will display here? Or am I totally missing the point?!

Link to comment
Share on other sites

Hai,

 

 

this is php file

test.php

 

<?php

 

include('Smarty.class.php');

 

// create object

$smarty = new Smarty;

 

$smarty->assign('left', 'value goes here');

 

#{$left } is represented as 'left' with out $ sysmbol

 

$smarty->display('test.tpl');

 

?>

 

The tpl file name is test.tpl

in tpl file you will have this

 

<div id= "left">{$left}</div>

 

folder structure refer smarty manual

 

 

Link to comment
Share on other sites

Thanks gunabalans,

 

 

think I have almost sot it now :) This is much appreciated.

 

However my (left.tpl), although now displays, is still displaying at the top of the page. If I show you what I have this may be easier:

 

index.php

 

<?php

 

include('config.php');

 

 

 

  $smarty->display('main.tpl');

 

 

 

  ?>

 

 

Config.php

 

<?php

 

 

 

$host = ""; //database location

$user = ""; //database username

$pass = ""; //database password

$db_name = ""; //database name

 

 

 

//database connection

$link = mysql_connect($host, $user, $pass);

mysql_select_db($db_name);

 

if (!$link) {

 

  echo "connection error"; //Display the text inside the quotes.

 

}

 

 

include('libs/Smarty.class.php');

  $smarty = new Smarty;

  $smarty->template_dir='templates';

  $smarty->compile_dir='templates_c';

  $smarty->cache_dir='cache';

  $smarty->plugins_dir[] = 'customplugins';

  include('header.php');

 

  $smarty = new Smarty;

  $smarty->assign('left');

  $smarty->display('left.tpl');

 

  ?>

 

 

header.php

 

<?php

 

$smarty->display('header.tpl');

 

 

?>

 

Inside the left.tpl I have this:

 

<div id= "left">{$left}</div>

 

The header.tpl has is linked to a .css style sheet, if this is not needed or conflicting I can delete this, as it is produced only by the .css template I was using in dreamweaver.

 

Am I right in assuming I need to add something like:

 

$smarty = new Smarty;

  $smarty->assign('center');

  $smarty->display('main.tpl');

 

to the config.php and then something like:

 

<div id= "center">{$center}</div>

 

to the main.tpl?

 

would I need to add the div id's to my .css or are these fuctions auto recognised by smarty etc?

 

 

Again thanks so much for your help, I am very new to all this and this is my 1st foray outside of HTML!

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.