Chris Young <chris.wisefool@...> writes:

> 
> Hello all you PHPTalians, 
> I'm attempting to create an 'abbrev' custom PHPTAL modifier. It would, if 
the value is over a certain length, output it wrapped in an <abbrev> tag, 
with the value appended by '...'. I intended to use it like this:
> 
> 
> <span tal:content="abbrev: /some/path" />
> 
> To this end I devised this function:
> 
> 
> function phptal_tales_abbrev( $src, $nothrow ) {
> 
> 
>       return 'elided_html('.phptal_tales(' structure ' . $src, 
$nothrow).','.$limit.')';
> 
> }
> 
> 
> where elided_html does the magic. However, this generates an error: 
> 
> 
> PHPTAL Exception
> 
> 
> Invalid TALES path: 'structure /some/path', expected 'structure /some/
path' to be variable nameIs there something simple I'm missing? I 
understand I could do:
> 
> <span tal:content="structure abbrev: /some/path" /> 
> 
> and change the function accordingly, which isn't really that bad, but I'm 
curious as to if my original idea should work?
> 
> 
> Sincerely, 
> 
> Chris
> 
> 
> _______________________________________________
> PHPTAL mailing list
> PHPTAL@...
> http://lists.motion-twin.com/mailman/listinfo/phptal
> 

I'm not sure why the phptal_tales function won't accept that, probably 
because it doesn't accept keywords, only paths and modifiers. 

But even if it did,  I don't think that is going to work since you're 
passing 'structure some/path' into the php_tales function. The output of 
that function you're passing into your own function, which is what you will 
return to the template. You want the structure modifier to apply to the 
entire output of the elided_html function, not just the $src variable.

I think just putting the structure keyword in front of your modifier would 
be fine. But alternatively you could solve it with a preFilter in addition 
to your modifier.

class AbbrFilter extends PHPTAL_PreFilter {
    public function filter($src) {
        return str_replace("abbrev:", "structure abbrev:", $src);
    }
}

And on your TAL object call:
$tal->addPreFilter(new AbbrFilter());



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

Reply via email to