473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 15453
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brian | last post by:
I have an application that uses an array of values as a "lookup" table and smarty as a template engine. $lookup = "label"; $lookup = "label2"; $lookup = "label"; $lookup = "label2"; In my...
2
by: Daan | last post by:
Hello all, I'm having a little problem with Smarty. Getting it to work in a simple case went fine, but now I have the following situation: / /smarty /templates template.tpl /templates_c
1
by: Richard | last post by:
I need help. I have a smarty based program that I am modifying. I have a smarty template file that consists of smarty and HTML. I need to integrate some PHP database calls into it. My problem...
0
by: Conrad | last post by:
Hi, I'm very new to Smarty Template Engine and I'm using PHP 5.0.4 on the Windows XP Professional platform and I have the following question: When I change the 7th line of the script to use a...
2
by: J Huntley Palmer | last post by:
Whenever I put in a smarty variable in a link definition as : <a href="{$foo->bar}">foo</a>, it shows up as a literal as above in the link and not the contents of the variable itself....
7
by: Man-wai Chang | last post by:
1. How could concatenate two values into a string in the template? {section name=j start=0 loop=10 step=1} {section name=k start=0 loop=10 step=1} {assign var=xx...
2
by: Gene | last post by:
i'm newcomer in using smarty and i have problem like this: i want to have one template file (e.g. index.tpl) in this file section which use variable {$content}. and two files *.php which are using...
0
by: grezlik | last post by:
Hi! I have major problems with cakephp & smarty, (cake ver is 1.2 and smarty 2.6.18 ) there is a code (from cake/libs/view/view.php class SmartyView { .. .. ..
6
by: K. | last post by:
Hello! I have a problem with using php on smarty web page I would like to use a php code from this web page: http://www.money.pl/webmaster/# i.e.. <?php readfile...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.