• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Yet Another Smarty Thread

#21
[eluser]Jagar[/eluser]
Never mind I know the purpose of the second parameter of parse function. It's pretty useful.

I didn't I could assign multiple variables at once as follow:


Excellent work!

#22
[eluser]Jagar[/eluser]
Is there any way to use last modified date?

Thanks

#23
[eluser]Jagar[/eluser]
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;

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

Code:
A PHP Error was encountered

Severity: User Error

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

Filename: smarty/Smarty.class.php

Line Number: 1092

Thanks in advance

Jagar

#24
[eluser]sheri.nust[/eluser]
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 ?

#25
[eluser]Jagar[/eluser]
$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}

#26
[eluser]sheri.nust[/eluser]
@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

#27
[eluser]sheri.nust[/eluser]
@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

#28
[eluser]sheri.nust[/eluser]
@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

-----

#29
[eluser]Unknown[/eluser]
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?

#30
[eluser]nhantam[/eluser]
I use CodeIgniter 1.7.2

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

Code:
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
Code:
{foreach from=$todo_list item=$items}
    <li>{$items}</li>
{/foreach}

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

Code:
A PHP Error was encountered Severity: User 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

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

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

Code:
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 ?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.