Re: AW: [PHPTAL] Re: AW: Logical operators in PHPTAL

2010-10-05 Thread romtek
It seems to me that some people here believe that introduction of logical
operators to PHPTAL will force them (the people) to use these operators. It
will not. It will simply give more flexibility to those who want it, and
those who don't will be able to continue using PHPTAL the way they have.

By the way, I see no practical way to have templates without logic unless
they are very simple templates (in a simple application).
___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


AW: [PHPTAL] Re: AW: Logical operators in PHPTAL

2010-10-04 Thread Per Bernhardt
I want my templates to be as simple as possible.
They should not include any logic at all. So I never use php-modifier and I 
would also like to avoid some kind of AND or OR logical operators (although 
there are the smaller problem...).

But a template needs what I call state. The simplest example for me is the 
odd-even problem:

ul
li tal:repeat=item items class=${what to do here, odd or even?} /
/ul

The state of the rendering for the li-tag depends on the current item. So 
instead of writing php or some complex a ? B : c syntax, I just want to have 
somebody (model) who decides what to do for the current li.

Of course you can write a modifier for this like 
css-odd-or-even:repeat/item/odd. But I don't like modifiers the way they are 
implemented now. That is for two reasons:
1. You have do define something global (function or static method I think?) to 
let phptal find the modifier. You can't just register modifiers with the 
phptal-object like you can do it with filters or resolvers for example.
2. Each modifier has to parse it's argument(s) on his own.

What I would like to have is an object, which I can call a method on and pass 
arguments to.

So I would also say that you should strip the logical operators but implement a 
way to pass arguments to a method of a variable within the phptal context:

$p = new PHPTAL('template.html');
$p-oddHelper = new OddHelper();
$p-items = array(1, 2, 3);

ul
li tal:repeat=item items class=${oddHelper(repeat/item/odd)} /
/ul

I think it would be much simpler to extend the current tal-syntax only to allow 
parameters than to introduce logical operators. And it would keep the syntax 
simpler.

Kind regards,
Per





-Ursprüngliche Nachricht-
Von: phptal-boun...@lists.motion-twin.com 
[mailto:phptal-boun...@lists.motion-twin.com] Im Auftrag von Ivo Võsa
Gesendet: Montag, 4. Oktober 2010 11:54
An: Template Attribute Language for PHP
Betreff: Re: [PHPTAL] Re: AW: Logical operators in PHPTAL

Kornel Lesiński wrote:
 On 1 Oct 2010, at 18:46, Moritz Baumann wrote:

   
 I think the next step would be to work out syntax exactly:

 http://phptal.org/wiki/doku.php/improvedtales
   
 Hm, that page mentions a lot more than just logical operators. I 
 guess that’s what the negative feedback was about, not logical operators 
 inside tal:condition.

 The main difference between PHPTAl and other template engines is that 
 the syntax is quite simple and that the templates look clean. IMHO, 
 function calls and an equivalent to the ?: operator would add 
 unnecessary complexity to PHPTAL and spoil exactly what makes PHPTAL 
 unique and great. Support for logical operators inside tal:condition, 
 on the other hand, would make the php: modifier more or less unnecessary.
 


 I look at this differently: these are things I need, whether their syntax is 
 nice or not, so I'd prefer to make their syntax nicer.

 Perhaps arguments to functions is a step too far (and authors should be 
 required to write expression modifiers for these), but setting of class name 
 based on condition is a very common pattern and ternary operator is an awful 
 way to do it.

   
i personaly would like to avoid php: as much as possible, so for setting 
class name i use things like

function phptal_tales_iftrue($src, $nothrow) { $src = explode(',', trim($src)); 
return '(' . phptal_tales(trim($src[0]), $nothrow) . ' ? ' . 
phptal_tales(trim($src[1]), $nothrow) . ' : null)'; }

li tal:repeat=item list class=${iftrue: repeat/item/end, 'last'}.../li



___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: AW: [PHPTAL] Re: AW: Logical operators in PHPTAL

2010-10-04 Thread aaatoja
How did I solve the problem? (I'm working with ZF)

/**
 * PHPTAL context modifier (helper:)
 *
 * @param string $src
 * @param boolean $nothrow
 * @return string
 */
function phptal_tales_helper($src, $nothrow) {
  $src = 'helper-'.trim($src);
  return PHPTAL_Php_Transformer::transform($src, '$ctx-');
}

$view-addHelperPath($moduleDir.'/views/helpers', $moduleName.'_View_Helper');

And now I can use inside my templates:
a tal:attributes=href helper:url(array(), 'xxx')xxx/a

or

div tal:condition=helper:acl('Member') tal:content=structure 
helper:action('xx', 'xx')/div


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal