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

Easily changing templates

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
kaitlyn2004
Smarty Regular


Joined: 26 Apr 2007
Posts: 47

PostPosted: Sat May 26, 2007 4:20 pm    Post subject: Easily changing templates Reply with quote

My software is going to make use of Software. Apart from core changes, I'd prefer that users have to make as few changes as possible to the templates.

So, I was thinking for addons to simply use javascript to, for example, input a new field or a button. Javascript is already required, and prototype is used, so this would be very basic to accomplish.

What do you think of this option? Can you think of a better alternative?
Back to top
View user's profile Send private message
Dasher
Smarty Pro


Joined: 16 May 2007
Posts: 124
Location: Italy

PostPosted: Sun May 27, 2007 5:45 am    Post subject: Reply with quote

You'd probably end up creating a number of complex problems using JS to 'bolt on' functionality - not to mention the long term maintainence problems you'd create.

How, for instance, does the value associated with the new form item end up changing functionality or the processing or datastorage?

Maybe I'm missing something in what you're suggesting.
_________________
General Blog: http://dasher.wordpress.com
VoIP & SIP: http://blog.sipx.ws
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
kaitlyn2004
Smarty Regular


Joined: 26 Apr 2007
Posts: 47

PostPosted: Sun May 27, 2007 5:51 am    Post subject: Reply with quote

Ignoring backend work, I'm talking purely about the need to edit templates - whether to add text, an input field, button... new column.. whatever...
Back to top
View user's profile Send private message
Dasher
Smarty Pro


Joined: 16 May 2007
Posts: 124
Location: Italy

PostPosted: Sun May 27, 2007 6:24 am    Post subject: Reply with quote

Ok. But an input field needs to have it's data validated, the information needs to be processed or stored - bypassing the PHP wouldn't be a good idea.

In a general sense there are slightly more elegant and supportable ways of achieving this. Patching the output using JS is just creating more work for you - you need to consider browser JS support (quirks, etc), long term supportability of it, maintainence, etc.

An example is displaying a dataset of information in a table. In typical situations I have 3 arrays that I pass to a generic smarty template.

1) the data array
2) the Header array
3) (optional) a footer array

All of the above datasets are retrieved from either a database or a config file.


The general approach for the header array is (this is a rough example - I can provide something that's live in addition to the template if needed):

Code:
$tableHeaders = array(
  "fieldName" => array(
       "displayAs"=>"Column Name",  // (string)display column name
       "type"=>"int", // (string) hint as to the datatype of the field
       "reference"=>boolean, //boolean indicating if a lookup to a referenceData array is needed
      "dataPart"=>"field1", // (string) if a reference type then the key of the reference data from the dataset
      "actions"=>array("edit","delete"), // if actions exists then the actions are available for this row
/// .. and so on - I have about 10-15 possible attributes in an array
       ),
);


If I need to add an extra column to the above - say for displaying help - then it's a simple matter of updating the database with the information.

As a generic template is used - it gets all the clues for displaying the information it needs to render the output using the provided arrays.

The version similar to the above approach is also used for forms requiring data input. The added complexity with forms is that generally the data needs to be validated and processed in some way before being persisted.
_________________
General Blog: http://dasher.wordpress.com
VoIP & SIP: http://blog.sipx.ws
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
kaitlyn2004
Smarty Regular


Joined: 26 Apr 2007
Posts: 47

PostPosted: Sun May 27, 2007 6:32 am    Post subject: Reply with quote

It will get processed "properly", because there will also be plugins/hooks set on the php side to expect the extra data and handle it accordingly
Back to top
View user's profile Send private message
Dasher
Smarty Pro


Joined: 16 May 2007
Posts: 124
Location: Italy

PostPosted: Sun May 27, 2007 6:52 am    Post subject: Reply with quote

ok - cool.
_________________
General Blog: http://dasher.wordpress.com
VoIP & SIP: http://blog.sipx.ws
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
kaitlyn2004
Smarty Regular


Joined: 26 Apr 2007
Posts: 47

PostPosted: Sun May 27, 2007 7:02 am    Post subject: Reply with quote

So then, back to my original question...

For doing changes like adding an input field or something, is there a better alternative than actually requiring them to modify the template, then make sure it stays when/if they update the template?
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 -> Tips and Tricks 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