Part of the EllisLab Network
   
3 of 4
3
Yet Another Smarty Thread
Posted: 23 April 2009 10:28 AM   [ Ignore ]   [ # 21 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  145
Joined  04-22-2009

Is there any way to use last modified date?

Thanks

Profile
 
 
Posted: 23 April 2009 10:44 AM   [ Ignore ]   [ # 22 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  145
Joined  04-22-2009

I’m just experimenting right now, but soon I’ll be using it.

While doing that, I encounter an error while parsing a template in smarty where there are CI tags in it such as {elapsed_time} I can use {literal}{elapsed_time}{/literal} but I was wondering a way around this without using the literal tag.

The following is my code;

class Welcome extends Controller {

    
function Welcome()
    
{
        parent
::Controller();    
    
}
    
    
function index(){
        
        
#$this->load->view('welcome_message');
        
$this->smarty_parser->assign("message","test");
        
$data = array("message"=>"Welcome from smarty",
        
"another_test"=>"This is another test");
        
$this->smarty_parser->parse("ci:welcome_message",$data);
    
}

The following error is what i get from smarty engine

A PHP Error was encountered

Severity
User Error

Message
Smarty error[in ci:welcome_message line 60]syntax errorunrecognized tag 'elapsed_time' (Smarty_Compiler.class.phpline 599)

Filenamesmarty/Smarty.class.php

Line Number
1092 

Thanks in advance

Jagar

Profile
 
 
Posted: 31 August 2009 06:08 AM   [ Ignore ]   [ # 23 ]  
Grad Student
Rank
Total Posts:  31
Joined  08-21-2009

Hey
  Summer Student
i have followed your steps to use smarty in CI.
I used
function index()
{

      $this->load->_ci_varmap[‘smarty_parser’] = ‘smarty’;
      $this->smarty_parser->parse(“template.tpl”, $data);
}     

of my controller.

Kinldy tell me
1. what i have to used in $data variable.
2. And how i divide my page into different regions like header, footer ,content
3. what needs to be inserted into template.tpl ?

Profile
 
 
Posted: 31 August 2009 08:05 AM   [ Ignore ]   [ # 24 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  145
Joined  04-22-2009

$data is where you will load your tags that will be used by smarty template, for example if you have

$data[‘full_name’] = “John Doe”
$this->smarty_parser->parse(“template.tpl”, $data);

somewhere in your tpl you’ll have {full_name}

Profile
 
 
Posted: 01 September 2009 12:34 AM   [ Ignore ]   [ # 25 ]  
Grad Student
Rank
Total Posts:  31
Joined  08-21-2009

@Jagar

Thanx man.

but when i call template.tpl file , i got error


—————————
A PHP Error was encountered

Severity: User Warning

Message: Smarty error: unable to read resource: “template.tpl”

Filename: smarty/Smarty.class.php

Line Number: 1093
————————-

In my controller i have written

$data[“company”] = “EXcillo Pvt Ltd Company”;
     
$this->load->_ci_varmap[‘smarty_parser’] = ‘smarty’;
$this->smarty_parser->parse(“template.tpl”, $data);

————————-

And in application/config/smarty_parser.php file

i am using the following url for templates

$config[‘template_dir’] = dirname(APPPATH).“views”;

as i have placed my template.tpl in application/views folder (application/views/template.tpl)

I dont know why i am getting the above mentioned error

Profile
 
 
Posted: 01 September 2009 12:48 AM   [ Ignore ]   [ # 26 ]  
Grad Student
Rank
Total Posts:  31
Joined  08-21-2009

@Jagar

hey In my controller i just used

$this->smarty_parser->parse(“ci:template.tpl”, $data);

instead of

$this->smarty_parser->parse(“template.tpl”, $data);

the template is working fine…

But can u sort out the above problem when i used
  $this->smarty_parser->parse(“template.tpl”, $data);
statement

with regards
sheri

Profile
 
 
Posted: 01 September 2009 01:20 AM   [ Ignore ]   [ # 27 ]  
Grad Student
Rank
Total Posts:  31
Joined  08-21-2009

@Jagar

Also when i include file in template.tpl

{include file=“header.tpl”}

placed in application/views folder .

the same problem occurs

———-

A PHP Error was encountered

Severity: User Warning

Message: Smarty error: unable to read resource: “header.tpl”

Filename: smarty/Smarty.class.php

Line Number: 1093

——-

Profile
 
 
Posted: 27 September 2009 11:33 AM   [ Ignore ]   [ # 28 ]  
Summer Student
Total Posts:  1
Joined  09-27-2009

hi xtramix,

I am using your solution to integrate smarty into ci, it works perfect but the following throws an error:

{include file=“footer.tpl”} inside another template.tpl doesn’t seem to work.

Any idea how this should be solved?


djazzc


edit:

hmm, using:

<?php echo $this->smarty_parser->parse(“ci:footer.tpl”, $data); ?> inside the template.tpl works, any other “cleaner” solutions?

Profile
 
 
Posted: 10 May 2010 07:02 AM   [ Ignore ]   [ # 29 ]  
Summer Student
Avatar
Total Posts:  16
Joined  11-30-2008

I use CodeIgniter 1.7.2

blog file at system/application/conrollers/blog.php

function index()
    
{
        $this
->load->library('smarty_parser');        
        
$this->load->helper('html');        
        
$data['title''Your title';
        
$data['todo_list'= array('Clean House''Call Mom''Run Errands');        
        
$this->smarty_parser->parse("ci:content_template.tpl"$data); 
                
    


content_template.tpl at system/application/views/content_template.tpl

{foreach from=$todo_list item=$items}
    
<li>{$items}</li>
{/foreach} 

I run localhost/codeigniter_172/blog/
show error following:

A PHP Error was encountered SeverityUser Error

Message
Smarty error[in ci:content_template.tpl line 22]syntax error'foreach: 'item' must be a variable name (literal string) (Smarty_Compiler.class.php, line 1174)
Filename: smarty/Smarty.class.php
Line Number: 1095

Parse error: syntax error, unexpected T_ENDFOREACH in C:\xampp\htdocs\codeigniter_172\system\cache\%C^43F^43FD50D8%%ci:content_template.tpl.php on line 29 

when I add literal at system/application/views/content_template.tpl

{literal}
{foreach from
=$todo_list item=$items}
   
<li>{$items}</li>
{/foreach}
{
/literal} 

I run localhost/codeigniter_172/blog/
show the following:

My Todo List
{foreach from=$todo_list item=$items} 
{$items} {
/foreach} 
Copyright 
2010 CodeIgniter 1.7.2 

Could you solve problem, foreach array $todo_list with CI & Smarty ?

 Signature 

http://webdesignviet.wordpress.com

Profile
 
 
Posted: 10 May 2010 10:38 AM   [ Ignore ]   [ # 30 ]  
Summer Student
Total Posts:  10
Joined  11-16-2006

Try this:

{foreach from=$todo_list item=items}
   
<li>{$items}</li>
{/foreach} 

Note the missing $ symbol in the variable name.

hth.

Profile
 
 
   
3 of 4
3