fenom-template / fenom

Template Engine for PHP. Maintainers wanted!
Other
446 stars 108 forks source link

Way to call static methods (of Helpers for example) ? #48

Closed iJackUA closed 10 years ago

iJackUA commented 11 years ago

Are there any ideas how can I call statis helpers in Fenom tpls. or maybe it is planned in nearest future ?

For example I have tried to use Fenom with Yii framework, everything is fine except the issue I can't have nice syntax to call satic helpers like this

<?php echo CHtml::link(...) ?>

P.S. [offtop] Nice job with template engine, internal are very hard to undertand, but I like the usage and performance :)

bzick commented 11 years ago

This feature coming soon: {"Link: " ~ CHtml::link(...)} Or you can add tag $fenom->addFunctionSmart('link', 'CHtml::link'); (Fenom scan function arguments) and use tag link well:

{link ...}

P.S. internal are very hard to undertand because the project does not have the normal documentation :( but I'm working on it

iJackUA commented 11 years ago

Ok, will wait for this feature implementation from you

Or you can add tag $fenom->addFunctionSmart('link', 'CHtml::link');

I understand that I can do it right now , but you know, we are lazy programmers :) and CHtml helper has more then 50 functions except "link", also in Yii2 (that is in development now) all Widgets should be called in static way

MySuperMenu::widget($items, $options);

and it seems to me, there will be very much monkey-work to create manually a Fenom tag for all widgets

bzick commented 11 years ago

hm, did you want invoke it like function {... ~ MySuperMenu::widget($items, $options) ~ ...} or like tag{MySuperMenu::widget item=$items options=$options)} ?

iJackUA commented 11 years ago

Now it's my turn to say "hm..." :) both ways has some advantages in different cases but something like {... ~ MySuperMenu::widget($items, $options) ~ ...} seems more generic for me such approach do not force to "invent" anything, but just call static helpers as you have used to. This approach {MySuperMenu::widget item=$items options=$options)} is noce, but it looks like limited only to one case when static function receives only one param - array of key-values (or maybe I am wrong ?). So I'd rather vote for something like {... ~ MySuperMenu::widget($items, $options) ~ ...}.

bzick commented 10 years ago

Added in 1.5, see https://github.com/bzick/fenom/blob/develop/docs/syntax.md#static-method-support.

Notice: if the method is changed sequence of arguments template compilation must be cleaned.. This notice may be resolved in the next version automatically.