PDA

View Full Version : Smarty


riken
07-09-2005, 03:48 PM
Has anyone considered using Smarty (http://smarty.php.net/) instead of search/replace for template handling?

raminia
07-09-2005, 04:09 PM
nice stuff.

riken
07-18-2005, 06:31 AM
Thanks.

Do any of the other developers have an opinion on this? Any reason not to use smarty?

I'm currently knocking up a version of pixelpost using smarty, to see how easy/hard the conversion is. If people are interested I can post it here when it's finished.

raminia
07-18-2005, 06:53 AM
Doen't it make creating templates harder for ordinary users?

Connie
07-18-2005, 07:07 AM
I think it is not so much the problem now

why should we change something what is working for us?
there are other things which are more important:

new functionalities for example

we are all volunteering and I think we must not do work twice just to change the engine behind

and all AddOns which are out also must change

I do not see any sense in converting just for fun, if there are no basic reasons which urge to change something

and: there are many template - thingies out there, smarty and many others
so the next proposition will be to use another thing.. and what is the gain of functionality for this? I see nothing

and to be frank: I do not like to turn myself in a circle...
I like to go ahead, and if I work on something, it should make sense, give something new...

and please do not post any things like that here, (my opinion), we will run into a absolutely fruitless discussion. (catholic or protestant, white or green, apples or oranges)

we should devote our skills to productive things

As I can say:

do something productive
love it or leave it (I saw this on american bumperstickers) :wink:
if you like to do something for your pleasure, do it
if that is making our way here problematic, leave it
never change a running system

and so on

I am absolutely not willing to discuss these things: why do you it this way and not this way? But I want it to be this way...
for that my time is too valuable

riken
07-18-2005, 07:46 AM
Doen't it make creating templates harder for ordinary users?
Only if the more advanced smarty tags are used.

why should we change something what is working for us? <snip>
Good point.

My only problem with the way it currently works is that, because the addons are run after the tags are searched/replaced, it's impossible to create addons that add to the template.

For example, I created an addon that would insert a template within another template (like the header/footer, but more generic). The addon worked, but the file being inserted couldn't have any pixelpost tags because they wouldn't get replaced. A templating engine would solve that problem.

I can post the addon once I get home from work. It was only about 5 lines.

Also I found this http://www.massassi.com/php/articles/template_engines/ which has a nice small template class.

Basically the problem I had with the addon could be fixed by doing all the tag replacement at the end of the processing, instead of in the middle, and before the addons are processed.

So I did have a reason for asking about templates :) Thanks for the reply.

Connie
07-18-2005, 07:59 AM
Basically the problem I had with the addon could be fixed by doing all the tag replacement at the end of the processing, instead of in the middle, and before the addons are processed.

That's the real point and that's on the list already.
We are aware of that and want all tags at hand in any template and that's why we put this topic already in the pipeline 8)

so you see, it's on the way.

raminia
07-18-2005, 11:15 AM
I think it is not so much the problem now

why should we change something what is working for us?


Yes it's not the problem now but I'm looking for the future.
The things we are using now may become obsolute if you don't track the user trends and changes.

Smarty is good for developper and I know it is excellent in that point but I still think it is more complicated than the simple HTML tags of PP. (That's a big superiority)

Do you think with this little modification poeple will abandon the PP dev streamline and leave all those templates and stuff and go with smarty? I don't think so. Let poeple think intutive. If we, dev team, want to guide the modifications we can assign open chanllenges that are critical for PP and ask people to work on it.

I think the main issue now is Templates but not smarty! Different, good templates for different tastes. I think poeple in the forum do not have a clear image of what we are doing. there should be some 'news' section in the site for that. Without that you could not expect poeple to underestand your longly debated concerns in the dev team!

riken
07-18-2005, 02:08 PM
I totally agree with you Raminia :)

Ok, so I've written a template engine for pixelpost, that works with the existing tags.

The template class is here: http://www.distantwisdom.net/~cameronm/pixelpost/includes/template.class.phps

The modified index.php is here: http://www.distantwisdom.net/~cameronm/pixelpost/index.phps (it's based on the one in CVS, with some modifications I made :))

The site is here: http://www.distantwisdom.net/~cameronm/pixelpost/

The main modification is to the str_replace and egrep_replace calls. Instead of

$tpl = str_replace('<SITE_TITLE>', $title, $tpl);
we have

$tpl->set('<SITE_TITLE>', $title);
The example I've used above calls the engine to render the result *before* the addons are called, so that it's backwards compatible. To take advantage of the template engine properly, the addons would have to be changed as detailed above aswell.

raminia
07-18-2005, 04:14 PM
In some pages the EXIF data is broken or invalid. the page is not loading completely. thumbs are not shown. btw, the EXIF data is not there but the tags are there
EXIF_EXPOSURE_TIME
EXIF_APERTURE
EXIF_CAPTURE_DATE
EXIF_FOCAL_LENGTH
EXIF_CAMERA_MAKE
EXIF_CAMERA_MODEL
EXIF_ISO
EXIF_FLASH
LANG_EXPOSURE_TIME
LANG_APERTURE
LANG_CAPTURE_DATE
LANG_FOCAL_LENGTH
LANG_CAMERA_MAKE
LANG_CAMERA_MODEL
LANG_ISO
LANG_FLASH

I think you didn't want them to be like this.

EDIT:
The problem is use of str_replace in template class. replace it with ereg_replace to work correctly.

raminia
07-18-2005, 04:16 PM
to argue...
I saw the template class. you mean by this way we can have more complex tags? for example
<IMAGE_NOTES place="comments"> and
<IMAGE_NOTES place="mainpage"> and things like that?

but I didn't see that in the template class. nothing more that the way PP was doing it was there.

riken
07-18-2005, 11:18 PM
EDIT:
The problem is use of str_replace in template class. replace it with ereg_replace to work correctly.
Fixed now. Thanks.

to argue...
I saw the template class. you mean by this way we can have more complex tags? for example
<IMAGE_NOTES place="comments"> and
<IMAGE_NOTES place="mainpage"> and things like that?

but I didn't see that in the template class. nothing more that the way PP was doing it was there.
Yes I do mean to have more complex tags, but first I wanted to show how easy it is to swap over to using a template engine. Then it would be possible to modify the template class to add features.

raminia
07-19-2005, 06:37 AM
Tell me more about how could we use it. in this way I assume we can have addon's with dynamic tags. for example for random addon I made before the number of random addon can be determined inside the tag and not neccessarily inside the db. something like
<RANDOM_THUMB value='3'> to show 3 thumbs in place.

are there fixed/standard parameter arguments that tags could have?

riken
07-19-2005, 08:34 AM
Tell me more about how could we use it. in this way I assume we can have addon's with dynamic tags. for example for random addon I made before the number of random addon can be determined inside the tag and not neccessarily inside the db. something like
<RANDOM_THUMB value='3'> to show 3 thumbs in place.

are there fixed/standard parameter arguments that tags could have?
I've been thinking about this problem, and I think the best solution would be some sort of callback. For example, to do <RANDOM_THUMB number="3">:

$tpl->setCallback("<RANDOM_THUMB>", "doRandomThumb");
and then

function doRandomThumb($args) {
$number = $args['number'];
// do some stuff, and put the code to replace in $result
return $result;
}
What's happening is you're setting a function to be called when the tag is to be replaced, and that function will return what the tag needs to be replaced with. I'll try to get something like this working of the next day or two.

raminia
07-19-2005, 09:44 AM
I know this is the solution but I wanted to know that if Smarty do grab the arguments from the tags or not.

riken
07-19-2005, 11:33 AM
I know this is the solution but I wanted to know that if Smarty do grab the arguments from the tags or not.
Ahh :) Smarty doesn't use normal html tags. Instead it uses {} so a smarty tag would look like {$random_image}.

Anyway, I've updated my template class to include tags with one option. I've done this as an example to show what is possible with a template engine, and to show it's easy to be backwards compatible.

raminia
07-19-2005, 02:56 PM
I remember somthing differenet from smarty that accepts tags like pixelpost. Rob some time ago mentioned that.....

seriocomic
07-20-2005, 05:18 AM
I believe something does need to be done sooner rather than later in regards to the tag system. Either introduce smarty or adopt created function tags like Wordpress.

Already I find myself limited in creating new templates because I want to include php coding in my template for conditional use but because the templates are imported as a string before being echo'ed out then the php isn't parsed.

riken
07-20-2005, 06:03 AM
Already I find myself limited in creating new templates because I want to include php coding in my template for conditional use but because the templates are imported as a string before being echo'ed out then the php isn't parsed.
I believe skennedy has a similar problem here http://www.pixelpost.org/forum/viewtopic.php?p=10969#10969

I think the biggest problem is that display logic is tied up in the code, rather than being available in the template.

However, there is something to be said for the ease of use the current solution has. The template designers don't need to know anything about programming to design templates.

Overall I think we could have the best of both worlds. This article http://www.massassi.com/php/articles/template_engines/ talks about reason to use PHP as your templating language, instead of Smarty for example. It should be easy for people to swap from <IMAGE_TITLE> to <?=$image_title?>, and that way non-programmers can stick to using simple tags while template programmers who know enough about PHP to use an if statement can do more complex templates.

But what would I know, I'm not a pixelpost developer :)

seriocomic
07-20-2005, 06:22 AM
I agree with just about every point you made :)

raminia
07-20-2005, 06:58 AM
I believe something does need to be done sooner rather than later in regards to the tag system. Either introduce smarty or adopt created function tags like Wordpress.

Already I find myself limited in creating new templates because I want to include php coding in my template for conditional use but because the templates are imported as a string before being echo'ed out then the php isn't parsed.

I think you can do that right now and the functionality is not limited. In WP when you design a template you are writing php codes but in PP when you write a template you write pure HTML codes with PP tags. you can add new functionality with writing php code similar to WP in the addons of PP and then use the addons along with your templates.

I don't think the functionality is affected but it's more clean.

BTW, I suggest to fetch <?php ?> codes from the template file and evaluating them seperately and the using ereg_replace. in this way we can have PHP codes running inside the current template system. but I don't know how!

My other suggestion is reading the tags with argument before processing the page. then extracting the arguments and passing them to the related addon. the addon uses thes argument and do some dynamic things and the produces the replacement of the tag. at the bottom of index.php (as it is not) the tags will be replaced with new values but the behavior is more dynamic and controlled by arguments that users put on their template.

I hate PHP coding inisde template. In the long run it will just mess up things...

riken
07-20-2005, 07:26 AM
BTW, I suggest to fetch <?php ?> codes from the template file and evaluating them seperately and the using ereg_replace. in this way we can have PHP codes running inside the current template system. but I don't know how!

<snip>

I hate PHP coding inisde template. In the long run it will just mess up things...
So are you for or against having PHP code in the template?

raminia
07-20-2005, 07:29 AM
I'm against. but meanwhile, I'm speculating.

seriocomic
07-20-2005, 07:41 AM
I think you can do that right now and the functionality is not limited. In WP when you design a template you are writing php codes but in PP when you write a template you write pure HTML codes with PP tags. you can add new functionality with writing php code similar to WP in the addons of PP and then use the addons along with your templates.

Yes, I can see this as working - it's just a change of mindset. But it does seem to be double processing.

BTW, I suggest to fetch <?php ?> codes from the template file and evaluating them seperately and the using ereg_replace. in this way we can have PHP codes running inside the current template system. but I don't know how!

My other suggestion is reading the tags with argument before processing the page. then extracting the arguments and passing them to the related addon. the addon uses thes argument and do some dynamic things and the produces the replacement of the tag. at the bottom of index.php (as it is not) the tags will be replaced with new values but the behavior is more dynamic and controlled by arguments that users put on their template.

Once again this seems to be overcomplicating what should be simple methodology - but I like your thinking.

I hate PHP coding inisde template. In the long run it will just mess up things...

While you may hate it, others may love it. It should come down to what's most practicable - but I'm only new around here :)

blinking8s
07-20-2005, 07:14 PM
no php in templates

about 10% of us will have a clue what the heck it is...many pixelpost users do not know html and have enough trouble with that.

I do think the template engine could be approved upon greatly though, we must brainstorm every detail about it possible and how it can be made better.

raminia
07-20-2005, 08:52 PM
let me clarify my points:
- addons are not double processing. they are simple php codes that run to produce some new html stuff. the payload of ereg_replace on the server site is ABSOLUTLY NEGLIGIBLE.

- I can challenge you to mention a functionality in writing a template for WP that you cannot do it with not greater complexity.

- PHP inside HTML is evil. Making them apart is a programming goal and that's way Smarty is there. As Blinking's just stated, PP's templates are HTML and even with this many people don't underestand how to modify it. I know many people that don't go near WP 'cause its complicated template. (1.2 templates where nightmare and 1.5 got better)

- I think you could have tags with arguments. Keeping the compatibility with simple tags but accepting new tags with arguments just like HTML itself.

seriocomic
07-21-2005, 04:59 AM
I agree with everything you said except...

- addons are not double processing. they are simple php codes that run to produce some new html stuff. the payload of ereg_replace on the server site is ABSOLUTLY NEGLIGIBLE.

Not double processing??

1. the entire template is pulled into a string variable
2. php is processed, arguments if then elsed etc
3. a replace is done on the entire string
4. the string is echoed/printed out.

compare this to php tags (included functions):

1. php is processed, arguments if then elsed etc
2. result is output

Granted this is an oversimplification of things and I AM NO EXPERT WHO KNOWS MORE THAN ANYBODY ELSE. It is/was in my opinion a legitimate point to raise.

Like I said before/elsewhere - I am only new to PP and fully appreciate the work you developers are doing. If it means hacking a few things to get my required level of functionality then so be it.

raminia
07-21-2005, 06:28 AM
I didn't want to be rude and you didn't get my point in that way.

the PP does not accept arguements right now. again, processing needed for echo and replace are negligible. I appreciate brainstorming here!
welcome to PP.

raminia
07-21-2005, 06:29 AM
compare this to php tags (included functions):
2. result is output


result is echoed!

seriocomic
07-21-2005, 06:43 AM
yup, echoed - what i meant.

:D