Hi all.

I love PHPTAL, but I always get in trouble when I need lots of different
number formatting
or some simple checks that can likely to be done directly in the template,
and that is not part of business logic, but part of layout logic - eg, how
layout built based
on internal representation.

I have recently tried new php framework named F3
http://fatfree.sourceforge.net

Can you please look into its templates section:
http://fatfree.sourceforge.net/#templates
... and especially section named "Template Expressions and Functions"

I just want to little discuss whether there is sense to port some ideas to
PHPTAL.

*1. IF-THEN-ELSE*. First at all, I remember there are many threads in this
mailing list
discussing "else" feature, and I do not know if there is any
outcome/decision.

I still do not understand why it's not implemented in some way,
taking into account its popularity based on email lists discussion.

As an additional idea, maybe it can be done with some namespace extension,
like talcheck:xxx, so we will not touch tal: and metal: namespaces.

The most universal way from my point of view is to have use-cases control
structure.

Examples that may be helpful or may throw any more ideas
(here I'm using both talcheck namespace and tal native namespace):

<talcheck:block check="php: true">
  <talcheck:block case="php: true">...</talcheck:block>
  <talcheck:block case="php: false">...</talcheck:block>
</talcheck:block>

<tal:block check="php: true">
  <tal:block case="php: true">...</tal:block>
</talcheck:block>

<tal:block check="php: 3">
  <tal:block case="php: 1">...</tal:block>
  <tal:block case="php: 2">...</tal:block>
  <tal:block caseelse="">...</tal:block>
</talcheck:block>

Looks like implementation is as simple as adding check context value, when
applicable,
and then use it for *case* and *caseelse* attributes and convert into
show/hide behavior like for condition attribute.

*2. Calling standard php functions*

After 7 years of making websites, I get convinced that using simple php
functions
does not necessarily mean moving business logic into template.

F3's "Template Expressions and Functions" section has very useful and simply
controlled
way to allow / disable native function calls.

I always end up writing up 10 formatting tal:modifiers for different
formatting way,
then using them in my template. Also I have to call some functions in php
before to pass
formatted values into template. All this happens just because it's not
looking great to call php functions
in your template, while you still want to do so - when these functions are
like helper functions
for layout, not for business logic.

Lets take a look on this function:
string number_format ( float $number , int $decimals = 0 , string $dec_point
= '.' , string $thousands_sep = ',' )

<span tal:content="php: number_format(a/b/c, 2)" />

The problem #1 here is that syntax becomes ugly when I want to still call
a/b/c but I cannot do so
because I'm inside PHP modifier.

What if we were able to do something like this:

<span tal:content="number_format(a/b/c, 2)" />

... or, following F3's idea to put expressions inside { and }...

<span tal:content="{number_format(a/b/c, 2)}" />
... and then it looks more like PHP insertion (but me personally I do not
like these figures)

So, why not? With having some special function to control what function
groups are allowed,
we then can easily detect whether it's php function call in some place, and
gracefully pass
correct values from context, like a/b/c in my example. This will make
formatting things more clear:

<span tal:content="number_format(account/amount, 2)" />

<tal:block condition="empty(account/insurance)" />
... take into account that it's not the same as exists: modifier

Another helpful example from F3 (which is often faster and simpler then to
create modifier):

<tr class="{(@key+1)%2?'odd':'even'}">

that in PHPTAL's way will be something like this:

<tr tal:attributes = "class { (key+1)%2? 'odd' : 'even' }">


*3. Combining attributes*

It's often useful to combine attributes. Example:

<div class="wrapper" tal:attributes="class wrapperExtendedClass | nothing "
/>

Is there a way to ADD more class values instead of replace them?
Eg, I want my final DIV to look like:

<div class="wrapper"/>
or
<div class="wrapper wrapper2"/>

I know, we can use tal:define to define with string: modifier, but it's much
of text to do,
and usually I end up building final class in php and passing it to the
template, which is more
trouble then if I would be able to just add wanted classes with phptal.
Examples:

<div class="wrapper" tal:*addattributes*="class wrapperExtendedClass |
nothing" />

or

<div tal:attributes="class theme/mainWrapperClass"
  tal:*addattributes*="class wrapperExtendedClass |
userDefinedTheme/wrapperClass | nothing;
      class wrapperWeatherClass | nothing"/>

can end up with:
*<div class="wrapper winter" />*
... in this example there was no wrapperExtendedClass defined, and
neither userDefinedTheme/wrapperClass was.



Let me know if all this makes sense.
Regards,

Anton Andriyevskyy
Business Automation & Web Development
_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to