Google

NukeCoder


View next topic
View previous topic
Post new topic   Reply to topic
Author Message
mralikorn




Joined: Oct 07, 2008
Posts: 32

PostPosted: Thu Mar 19, 2009 11:16 am
Reply with quote

When adding a custom php to make a new block.
How do i assign a template to that new block? They come out without the borders of original blocks.
Also any new blocks i create show up above the header. How do i get them to be on the left or right?

Is it possible you could create a "Template "php for blocks that I can fill in my own content. Where that new block refrences a template file all its own.
MrAliKorn
 
View user's profile Send private message
gotcha
Site Admin
Site Admin



Joined: Oct 25, 2004
Posts: 921

PostPosted: Thu Mar 19, 2009 1:10 pm
Reply with quote

Here is an example on how create a block using a template file using the included userinfo block.

The php code.... (app/Account/blocks/userinfo.php)
Code:
?php

// this gets an array of the users info from the db
$userInfo = $shop_user->userGetInfo($GLOBALS['loggedInID']);

// this assigns the array to the template
$tpl->assign('userInfo', $userInfo);

// this assigns the template to the $content variable which is then output
$content = $tpl->fetch($GLOBALS['current_theme'].'/account/blocks/userinfo.tpl');

?>


Now the Template code.....($GLOBALS['current_theme'].'/account/blocks/userinfo.tpl') as set in the above php file
Code:

{* assign the block title *}
{assign var="block_title" value="Your Info"}

{* open the block  *}
{include file="$current_theme/blocks/block2-open.tpl"}

{* block content goes here  *}
<div><strong>User Name:</strong><br><img> {$userInfo.username}</div>
<div><strong>Email:</strong><br><img> {$userInfo.email}</div>
<div><strong>Joined:</strong><br><img> {$userInfo.reg_date|date_format:"%D"}</div>

{* close the block  *}
{include file="$current_theme/blocks/block2-close.tpl"}


A couple of notes about the template files..
you can only use assigned variables in the templates.
Variables in the template files are accessed like so.

In normal php
Code:
echo $var;


in the template
Code:
{$var}


In normal php
Code:
echo $var['key'];


in a template
Code:
{$var.key}


That should be a good starting point. Depending on what you are trying to do there are easy ways to get items, images, etc. Let me know if you have any questions.
 
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 5 Hours
Forums ©