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

Different ways of embedding template "code"?

 
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
devnul
Smarty Rookie


Joined: 26 Aug 2003
Posts: 32

PostPosted: Tue Sep 09, 2003 12:00 am    Post subject: Different ways of embedding template "code"? Reply with quote

Hello,

This relates, somewhat, to the issue of using a GUI design tool in conjunction with Smarty.... I had an idea the other night and it works for a lot of things, but not quite enough... I was wondering if this is:

A) even a smart(y) thing to do?

... if so..

B) is there anyway to improve it..

Let me start off with a "simple" example of a form INPUT tag:

Code:

<input type="text" name="first_name" value="My, Myself, and I" size="60">

... turning that into a Smarty template:

<input type="text" name="first_name" value="{$user.first_name}" size="60">


.. immediately I see that from a designers perspective they can potentially [fm]uck this up by screwing around with the value (which they might want to do in order to see what it looks like/etc...

So, what I was contemplating was doing this:

Code:


<form name="User" smartytag="TRUE">
<input type="text" name="first_name" value="Go ahead and type whatever you want to here you silly designer!" size="60" smartytag="TRUE">
</form>



... This is where it gets interesting... Basically I setup a prefilter to preprocess the form BEFORE it's compiled... It looks for tags which contain the "smartytag" element.. Upon seeing one, it will do certain things depending on what type of tag it is, as follows:

FORM
Grab the "name" attribute, which will equate to an object (in this case the "User" object, store it in "$obj" for this example).

INPUT (type="text")
Store the "name" attribute in $name.
Remove the "value" tag, replacing it with something like: {$obj->data[$name]}.
Add "maxlength" attribute to indicate the maximum size of this field

-----

So far I have used this method successfully with SELECT, INPUT (type = radio, checkbox, hidden, and text), and TEXTAREA.

.. The problem is it's not "generic enough".... I find myself continuously revisiting the prefilter code in order to hack it up more to handle some "special case" I had not contemplated....

I also am looking for a way to do something similar with TABLE/TR/TD tags (used to display database results/etc) and SPAN tags (used to embed dynamic content anywhere)....

Am I waaaay off-base on this one?

The thing I really like about this is:

A) since it's a prefilter it's impact on performance is minimal (only updated pages get "reprocessed")
B) It would hopefully allows a designer complete freedom to do whatever they want - at least that's what I am trying to get to.

What I don't like about it:
A) It's more code to write initially
B) It's seems sort-of like a 'hack' to me
C) Dealing with IF/ELSE seems might problematic... ;-(

...
Perhaps when starting this line of thinking I was asking the wrong question to begin with.... I can see that if I am the only one coding/designing that the traditional Smarty approach gives me a great mix.. But, as soon as I start thinking that I need to turn over responsibility of site design to a 3rd party (I.E. customer) I can see them screwing up the templates and breaking the site... Granted, it's a lot better then some other methods..

So maybe the question here is: how can I give the absolute *MOST* control to designers while maintaining the application logic?

Hope all of this makes sense.. I appreciate any thoughts ya'all have on this...

- Greg
Back to top
View user's profile Send private message Visit poster's website
muppie
Smarty Rookie


Joined: 27 Apr 2003
Posts: 20

PostPosted: Sat Sep 13, 2003 8:49 pm    Post subject: Reply with quote

This seems like a good idea... perhaps you only need to make your code so that it is easy to add more tag type, perhaps with a simple definition of tag / replacement using regex? So when you encounter a new tag to add, just add a single line to the regex list ?

And this regex list is in the array so you just do preg_match..

I wrote my own class to handle form generation / validation and the HTML itself doesn't contain any real tag... the form looks like:

{$form.start} instead of <form .....>
{$form.controls.first_name} instead of <input type="text" name="first_name">

This gives me the freedom to change things e.g. from a text input to a drop down select box from code and the template doesn't need to change. But on the other hand I need to find a way to let the template designer specify things like css class and visual characteristics. This can probably be fixed using your method with prefilter or use a custom smarty tag.

I prefer your method as it makes the form looks "normal"
Perhaps I can simply write a prefilter to convert this as well... this is something I have been contemplating but too lazy to do it since I'm the only one editing the template hehe
Back to top
View user's profile Send private message
devnul
Smarty Rookie


Joined: 26 Aug 2003
Posts: 32

PostPosted: Mon Oct 06, 2003 10:03 am    Post subject: Reply with quote

Yeah, I've been giving this some thought lately.. I';m not quite sure how to go forward with it, right now I just need to get this project finished.. After that I think I'm going to dive into it a bit more....

I'll keep you updated as it progresses.. Wink

- Greg
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