Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

assign + caching other files

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Wed Sep 24, 2003 2:48 pm    Post subject: assign + caching other files Reply with quote

hi,

i got a small cms in my shopsystem, where you ca add txt/html/php etc files as "content" for display.

is there any way to assign the file "output" in php to smarty , like the fetch() for templates ?
or is there any way to include a non template file with smarty tags in the template ? ( {include} wont work).

regards+thx,
mario
_________________
[quote]
http://www.xt-commerce.com
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Sep 24, 2003 4:38 pm    Post subject: Reply with quote

mzanier_XTC, how do you do?

I think you want to look at PHP's output buffering.


Last edited by boots on Thu Sep 25, 2003 8:38 pm; edited 2 times in total
Back to top
View user's profile Send private message
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Thu Sep 25, 2003 11:50 am    Post subject: Reply with quote

re,

well, normaly ill used in my php file without tpls.

include(DIR_FS_CATALOG.'media/content/'.$shop_content_data['content_file']);

if i go for ob

Code:

<?php
function callback($buffer) {
 
 $smarty->assign('file',$buffer);

}
ob_start("callback");

include(DIR_FS_CATALOG.'media/content/'.$shop_content_data['content_file']);

ob_end_flush();
?>


does smarty cache the content of file also ?

regards,
mario
_________________
[quote]
http://www.xt-commerce.com
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Sep 25, 2003 12:21 pm    Post subject: Reply with quote

yes, it does. if caching is enabled the *output* of the template is cached.
the old value of $file will be re-displayed.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Thu Sep 25, 2003 2:27 pm    Post subject: Reply with quote

well i tried a bit with OB, the problem is, that i cant asign the output.

if ill use:

Code:

<?php
function callback($buffer) {

$smarty->assign('file',$buffer);

}
ob_start("callback");

include(DIR_FS_CATALOG.'media/content/'.$shop_content_data['content_file']);

ob_end_flush();
?>


ill get white screen, if ill use an echo $buffer; within the callack function, nothing getting displayed, only if ill use return $buffer; the file output is on screen, but displaced.

you got any hint how to fetch this into a var ? thats kinda asuming..

regards+thx,
mario
_________________
[quote]
http://www.xt-commerce.com
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Sep 25, 2003 2:42 pm    Post subject: Reply with quote

you have to say "global $smarty" in your callback-function.
or simply do:

[php:1:61c16a6537]ob_start();
do-the-include-foo
$smarty->assign('file', ob_get_contents());
ob_end_clean();
[/php:1:61c16a6537]

and omit your callback-function.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Thu Sep 25, 2003 3:07 pm    Post subject: Reply with quote

hm,,

now the file get fetched, but Laughing

ob_start();

if (strpos($shop_content_data['content_file'],'.txt')) echo '<pre>';
include(DIR_FS_CATALOG.'media/content/'.$shop_content_data['content_file']);
if (strpos($shop_content_data['content_file'],'.txt')) echo '</pre>';
$smarty->assign('file',ob_get_contents());
ob_end_flush();

->> ill get also the output of the include (like normal include) on my screen, + the output in the smarty variable.
_________________
[quote]
http://www.xt-commerce.com
Back to top
View user's profile Send private message Visit poster's website
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Thu Sep 25, 2003 3:11 pm    Post subject: Reply with quote

Embarassed

ob_end_clean();

working Wink)

thx for help+happy we,
mario
_________________
[quote]
http://www.xt-commerce.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP