Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call chaining in CoTemplate #1263

Closed
macik opened this issue Oct 25, 2013 · 3 comments
Closed

Call chaining in CoTemplate #1263

macik opened this issue Oct 25, 2013 · 3 comments

Comments

@macik
Copy link
Member

macik commented Oct 25, 2013

Have some suggestions for XTemplate methods…

First
Make XTemplate->parse() to return self object, so we can use basic chain to simplified constructions like this:

$t->parse('MAIN');
$t->out('MAIN');

to this:

$t->parse('MAIN')->out('MAIN');

Second
Often while working with complex templates with nested blocks we need to do something like this:

$t->parse('MAIN.SUBBLOCK.INNERBLOCK');
$t->parse('MAIN.SUBBLOCK');
$t->parse('MAIN');

Suggest to add XTemplate->parseChain() method that can do it for us with simply:

$t->parseChain('MAIN.SUBBLOCK.INNERBLOCK');
@trustmaster
Copy link
Member

I agree with the first one, that's a great idea!

The second one isn't so brilliant in my opinion. Explicit is better than implicit and by saving a few calls the code looses much of its clarity for people who don't know what exactly parseChain() does. And it's more bug-prone if you forget to split it into multiple calls later when you change code.

@trustmaster
Copy link
Member

Now you can chain different XTemplate calls, examples:

$t->assign(array(
    'FOO' => 'bar',
))->parse('MAIN.BLOCK');
$t->parse()->out();
$t->parse('MAIN.SUBBLOCK.INNERBLOCK')->parse('MAIN.SUBBLOCK')->parse('MAIN');

A few other methods support chaining too.

@macik
Copy link
Member Author

macik commented Oct 27, 2013

Excellent!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants