Great Idea!

22 views
Skip to first unread message

Dan

unread,
Apr 1, 2011, 4:53:43 PM4/1/11
to jSmart
Just wanted to say thanks for the hard work. I've not used it yet I'll
let you know how I get on.

Ideally I would like to be able to use the same templates on both
server and client. Although that might sound odd it relates to using
templates with offline/html5.

I'll let you know how I get on.


Dan

Max Miroshnikov

unread,
Apr 5, 2011, 7:53:21 AM4/5/11
to jSmart
Thank you, Dan!

I'll try to answer any of your questions here, since there is no
documentation available for now

Of course, you can use the same templates both for php and jscript
unless some specific features are used (e.g. {php} tags, etc.)

Max

Dan

unread,
Apr 18, 2011, 5:09:44 AM4/18/11
to jSmart
Hi Max,

Just a few questions.

Can you assign the template after the jSmart object is created?
Can you use assign to add data to the template?

So using smarty I can do:

$test = new smarty();
$test->assign('key',$value);
$test->fetch("test.tpl");

Also I'll probably look to do template inheritance (http://
www.smarty.net/inheritance) is this on your radar?

My Javascript is ok but I'm quite heavily reliant on 3rd party JS.
What I expect I'll try to do is to extend the jsmart object (using
http://javascriptmvc.com/docs.html#&who=jQuery.Class) and wrap JQuery
Ajax round it to fetch templates. The PHP functions I use within
templates I'm hoping/seem to be part of phpjs.org.

Thanks,


Dan

Max Miroshnikov

unread,
Apr 18, 2011, 11:39:32 AM4/18/11
to jSmart
Hi Dan

> Can you assign the template after the jSmart object is created?
> Can you use assign to add data to the template?

Not exactly, but you can do something like this:

var test = new jSmart(testTpl); //the template is compiled now
var data = {
'key' : 'value'
};
var res1 = test.fetch(data); //it's cheap to call fetch() many
times since the template has been compiled already
data['key'] = 'another_value';
var res2 = test.fetch(data);


>Also I'll probably look to do template inheritance (http://www.smarty.net/inheritance) is this on your radar?

Inheritance is supported in the current version:
var test = new jSmart(parentTpl, childTpl, grandChildTpl, ...);
use {block} in child templates just like it's described here:
http://www.smarty.net/docs/en/language.function.block.tpl
{extends} is not supported since there is no need for it

BUT there is one feature that the current version of jSmart completely
misses - variable modifiers
I hope a new version with support of modifiers will be out soon


Max



On Apr 18, 1:09 pm, Dan <webmas...@d2g.org.uk> wrote:
> Hi Max,
>
> Just a few questions.
>
> Can you assign the template after the jSmart object is created?
> Can you use assign to add data to the template?
>
> So using smarty I can do:
>
> $test = new smarty();
> $test->assign('key',$value);
> $test->fetch("test.tpl");
>
> Also I'll probably look to do template inheritance (http://www.smarty.net/inheritance) is this on your radar?
>
> My Javascript is ok but I'm quite heavily reliant on 3rd party JS.
> What I expect I'll try to do is to extend the jsmart object (usinghttp://javascriptmvc.com/docs.html#&who=jQuery.Class) and wrap JQuery

Dan

unread,
Apr 19, 2011, 4:39:42 AM4/19/11
to jSmart
Hi Max,

The issue I face is that I would like to setup Smarty in a base view
where all views extend from this.

The way it currently stands I would have to setup the jsmart in each
view as it's tied to the template on creation.

As I'm using indexeddb I have started building classes that pull data
back into the object. This allow the class to do the formatting (Which
makes modifiers less of a priority to me) however this means I
commonly pass this class directly to the template and call the methods
on that class. I'm unsure weather I can pass these classes (Models)
within the json argument if you know off the top of your head thanks
otherwise I'll have a look when I get a chance.

Also as I'm heavily using application cache and indexeddb, with this
in mind is there a mechanism to interact with the object to perform
client based caching?

It would be nice (Sorry to be a pain in the ....) that we could handle
extends (maybe a callback?) this means that we can call a template
without having to know which parent, grandparent etc it belongs to. So
my idea would be that the callback would be given the content of the
file attribute and then return the parent template containing it's
parents etc etc.

Thanks for all your hard work. I think as HTML5 kicks off, MVC type
structures for javascript will grow and this project will add real
value. There is a lot of competition arising in this area from the big
players (i.e. jquery templates) but using smarty's well established
style could set the project apart from the rest.

Dan


Max Miroshnikov

unread,
Apr 19, 2011, 9:22:49 AM4/19/11
to jSmart
Hi Dan,

You can pass an object as a part of data parameter for the fetch()
method and call "methods" of this object in you template, e.g.

var data = {
'foo' : {
'bar' : function(s) { return 'foo says: '+ s; }
}
};

var t = new jSmart(someTpl);
t.fetch(data);

in 'someTpl' template:
{$foo.bar('Hello')} {* this should output 'foo says: Hello' *}

I hope I answered your question about objects.


Thank you, for your advice on templates inclusion with callbacks.
This is a great idea, I should have thought about it myself :)
I'm going to make support for {extends} and {include} tags and just
leave it up to a user of jSmart to provide a template in a
callback(tplName) function
I will write here as soon as a new version is available for
downloading.



Max

Dan

unread,
Apr 21, 2011, 6:34:19 AM4/21/11
to jSmart
Not sure how you do it but can you give me access to edit the wiki?

I've run into a few issue using jSmart with jQuery and would like to
put the detail on the wiki.

I'm not quite sure of the answer for this but some of the functions
used within jSmart are included in the other libraries like objMerge.
Also I see that you only have the minimised version for download, can
you also put the full fat version as it makes debugging (issues like
the above) easier.

Regards,


Dan

Max Miroshnikov

unread,
Apr 21, 2011, 8:22:05 AM4/21/11
to jSmart
Hi, Dan

I've added your email as a project contributor with a permission to
edit project's wiki.

Didn't quite understand what the problem with names of functions is. I
hope you will explain it in more details on jSmart site.
You can also use Issues page to report bugs. It seems to be open for
everyone.

I will put both minimized and full files of the new release on
Download page.

Regards,
Max

Max Miroshnikov

unread,
Apr 25, 2011, 7:40:43 AM4/25/11
to jSmart
Hi, Dan

There is a new version available, {include} and {extends} tags are now
supported
Here is documentation - http://code.google.com/p/jsmart/wiki/IncludeTemplates



On Apr 19, 12:39 pm, Dan <webmas...@d2g.org.uk> wrote:

Dan

unread,
May 3, 2011, 3:38:35 AM5/3/11
to jSmart
Hi Max,

Just back from a break I will hopefully have time later this week to
test.

Regards,


Dan

On Apr 25, 12:40 pm, Max Miroshnikov <miroshni...@gmail.com> wrote:
> Hi, Dan
>
> There is a new version available, {include} and {extends} tags are now
> supported
> Here is documentation -http://code.google.com/p/jsmart/wiki/IncludeTemplates

Dan

unread,
May 12, 2011, 4:22:22 AM5/12/11
to jSmart
I can confirm that I have extends working and I haven't found any
issues yet.

Regards,

Dan
Reply all
Reply to author
Forward
0 new messages