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

Feature Request: $smarty->template (string)

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
gurubob
Smarty Rookie


Joined: 14 Jul 2003
Posts: 8
Location: Hertfordshire, UK

PostPosted: Fri Aug 08, 2003 5:53 pm    Post subject: Feature Request: $smarty->template (string) Reply with quote

Hi,

I've been dev'ing in Smarty lately (fab product Razz ). I've been coding my apps along the lines of ...

Code:

$s = new Smarty;
if (condition) {
    $s->template = 'template_a.tpl';
} else {
    $s->template = 'template_b.tpl';
}
$s->display($s->template);


I think it would be nice if all parameters for display() were optional and Smarty would use the template class variable if it was set. It makes my life easier. Just a thought.

Cheers,

- Bob -
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
AZTEK
Smarty Pro


Joined: 16 Apr 2003
Posts: 235
Location: Purdue University

PostPosted: Fri Aug 08, 2003 6:04 pm    Post subject: Reply with quote

You could easily extend the smarty class to do that just add a member variable and create your own display something like [php:1:a399c5313c]<?php
class MySmarty extends Smarty {
var $template;

function MySmarty() {
$this->template = "default.tpl";
}

function display() {
parent::display($this->template);
}
}
?>[/php:1:a399c5313c]thats just a quick write up I didnt test it so shoot me if it doesnt work. Then instead of $s = new Smarty; do $s = new MySmarty;
_________________
"Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane
Back to top
View user's profile Send private message Visit poster's website
gurubob
Smarty Rookie


Joined: 14 Jul 2003
Posts: 8
Location: Hertfordshire, UK

PostPosted: Fri Aug 08, 2003 7:10 pm    Post subject: Reply with quote

Hey Aztek,

Thanks for the code example - I haven't really got around to extending existing classes in PHP yet but I might just have to do that.

Cheers! Wink
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
boots
Administrator


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

PostPosted: Fri Aug 08, 2003 7:17 pm    Post subject: Reply with quote

Yes, I heartily agree with Aztek--conveniences such as that are best left to a custom class which inherits Smarty.

off-topic: I think I am biased by the way I use Smarty, but in my mind, even display() should be left out of the core. You'd be forced to use fetch() instead, making it clear that Smarty provides only transformation services and not delivery services. That, of course, is only my opinion Wink but since you typically require a request broker when using Smarty, it seems like a reasonable choice to me and permits for better delineated pipelining of the production chain. Some may suggest an integrated front controller but I still think there is merit in keeping the core compact and single-purposed.
Back to top
View user's profile Send private message
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 -> Feature Requests 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