Discussion:
use of 'structure' with custom PHPTAL modifier
Chris Young
2013-09-03 21:27:56 UTC
Permalink
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 name*
Is 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
Bas Kooij
2013-09-09 12:52:09 UTC
Permalink
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,
<span tal:content="abbrev: /some/path" />
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
<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
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());
Kornel Lesiński
2013-09-09 21:58:02 UTC
Permalink
Post by Chris Young
*Invalid TALES path: 'structure /some/path', expected 'structure
/some/path' to be variable name*
<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?
Bas is right, phptal_tales expects paths, but not the structure keyword.

What you get from phptal_tales is unescaped data - equivalent of
"structure" already. It's just that complete result of all modifiers is
going to be escaped afterwards.

I see what you're trying to do, and some ability do disable escaping from
within modifiers would be useful, but unfortunately there's no API for it
currently.
--
regards, Kornel
Loading...