469,327 Members | 1,200 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

Smarty template via string variable?

Hello,

I am trying to work out how to have smarty use a string's contents as the
display-> template..
ie:
$smarty->display($buffer);

obviously $buffer isn't a filename, but a smarty template inside a string
variable. Take this example:

<snip>
<?php
ob_start('ob_callback');
$smarty = new smartyLocal();
$smarty->assign('var1', 'test');
ob_callback($buffer) {
$smarty->display($buffer);
}
?>

<html><head><title>page</title></head>
<body>
{$var1}
</body>
</html>

EOF

What do you guys think? Anyway to do this?
Jul 17 '05 #1
4 15170
I know, that should have been "function ob_callback($buffer)", I just meant
it as an example.
"Brian" <cpnmscg02 (@) sneakemail.com> wrote in message
news:pvJEb.402610$Dw6.1250589@attbi_s02...
Hello,

I am trying to work out how to have smarty use a string's contents as the
display-> template..
ie:
$smarty->display($buffer);

obviously $buffer isn't a filename, but a smarty template inside a string
variable. Take this example:

<snip>
<?php
ob_start('ob_callback');
$smarty = new smartyLocal();
$smarty->assign('var1', 'test');
ob_callback($buffer) {
$smarty->display($buffer);
}
?>

<html><head><title>page</title></head>
<body>
{$var1}
</body>
</html>

EOF

What do you guys think? Anyway to do this?

Jul 17 '05 #2
Brian <cpnmscg02 (@) sneakemail.com> wrote:
Hello,

I am trying to work out how to have smarty use a string's contents as the
display-> template..
ie:
$smarty->display($buffer);

obviously $buffer isn't a filename, but a smarty template inside a string
variable.


Looks like a RTFM to me:
http://smarty.php.net/manual/en/temp....elsewhere.php

<q>
Templates from other sources

You can retrieve templates using whatever possible source you can access
with PHP: databases, sockets, LDAP, and so on. You do this by writing
resource plugin functions and registering them with Smarty.
</q>

--

Daniel Tryba

Jul 17 '05 #3
Hi Brian,

You can use eval to parse your template code before outputting.
For example if you have a variable $buffer in php file

$buffer =
'<html><head><title>page</title></head>
<body>
{$var1}
</body>
</html>';

$smarty->assign('var1', 'test');
$smarty->assign('buffer', $buffer);

You can code your smarty template file as follows

{eval var=$buffer assign="parsedBuffer"}
{$parsedBuffer}
-- Rahul


"Brian" <cpnmscg02 (@) sneakemail.com> wrote in message news:<qwJEb.402615$Dw6.1250605@attbi_s02>...
I know, that should have been "function ob_callback($buffer)", I just meant
it as an example.
"Brian" <cpnmscg02 (@) sneakemail.com> wrote in message
news:pvJEb.402610$Dw6.1250589@attbi_s02...
Hello,

I am trying to work out how to have smarty use a string's contents as the
display-> template..
ie:
$smarty->display($buffer);

obviously $buffer isn't a filename, but a smarty template inside a string
variable. Take this example:

<snip>
<?php
ob_start('ob_callback');
$smarty = new smartyLocal();
$smarty->assign('var1', 'test');
ob_callback($buffer) {
$smarty->display($buffer);
}
?>

<html><head><title>page</title></head>
<body>
{$var1}
</body>
</html>

EOF

What do you guys think? Anyway to do this?

Jul 17 '05 #4
"Brian" <cpnmscg02 (@) sneakemail.com> wrote in message news:<pvJEb.402610$Dw6.1250589@attbi_s02>...
Hello,

I am trying to work out how to have smarty use a string's contents as the
display-> template..
ie:
$smarty->display($buffer);

obviously $buffer isn't a filename, but a smarty template inside a string
variable. Take this example:

<snip>
<?php
ob_start('ob_callback');
$smarty = new smartyLocal();
$smarty->assign('var1', 'test');
ob_callback($buffer) {
$smarty->display($buffer);
}
?>

<html><head><title>page</title></head>
<body>
{$var1}
</body>
</html>

EOF

What do you guys think?


http://www.phpbuilder.com/annotate/m...hp3?id=1013434
http://www.phpbuilder.com/annotate/m...hp3?id=1013711
http://www.phpbuilder.com/annotate/m...hp3?id=1013461

--
http://www.wikipedia.org/wiki/P.A.Sangma - Yet-another Mahatma
Email: rrjanbiah-at-Y!com
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Brian | last post: by
2 posts views Thread by Daan | last post: by
1 post views Thread by Richard | last post: by
reply views Thread by Conrad | last post: by
2 posts views Thread by J Huntley Palmer | last post: by
7 posts views Thread by Man-wai Chang | last post: by
2 posts views Thread by Gene | last post: by
reply views Thread by grezlik | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.