Closed ryan-mahoney closed 9 years ago
Thanks Ryan, please consider the following:
array()
instead of []
to have it working on 5.3 too.I like to use my helpers like this:
{{#SomeHelper format="xyz" value="123"}}
but... there is not convenient way to access these values... until now ;)
$args = $template->parseTagAttributes($args);
You can merge this Pull Request by running
git pull https://github.com/Opine-Org/handlebars.php master
Or view, comment on, or merge it at:
https://github.com/XaminProject/handlebars.php/pull/44 Commit Summary
- parse HTML style attributes and values
- typo
File Changes
- M src/Handlebars/Template.phphttps://github.com/XaminProject/handlebars.php/pull/44/files#diff-0(29)
Patch Links:
- https://github.com/XaminProject/handlebars.php/pull/44.patch
- https://github.com/XaminProject/handlebars.php/pull/44.diff
— Reply to this email directly or view it on GitHubhttps://github.com/XaminProject/handlebars.php/pull/44 .
Sorry -- didn't intend to push my composer change, that was for my own testing. Re: other changes, I will go ahead and do so. Thanks!
@virtuecenter could you rebase this PR to remove the extra commits and write tests? or I shall finish it myself?
Consider the following alternate syntaxes for achieving the same flexibility.
{{#SomeHelper format=xyz&value=123}}
{{#SomeHelper format=xyz value=123}}
{{#SomeHelper format=xyz;value=123}}
{{#SomeHelper format=xyz,value=123}}
{{#SomeHelper format=xyz-value=123}}
http_build_query($arr)
to generate the parameter stringparse_str($str, $arr)
to parse the parameter string if the separator is &
parse_str_separator
that uses parse_str
in case the separator is &
parse_str_separator
function for parsing HTTP headersfunction parse_str_separator($str, &$array, $separator = '&') {
if ($separator === '&') {
parse_str($str, $array);
} else {
$array = array();
preg_match_all('@([^=]+)=([^\\' . $separator . ']*)' . $separator . '?\\s?@', $str, $matches, PREG_SET_ORDER);
foreach ($matches as $m) {
$array[$m[1]] = $m[2];
}
}
}
$query = http_build_query(array('format' => 'xyz', 'value' => '123'));
var_dump($query);
parse_str_separator($query, $arr);
var_dump($arr);
$separator = ' ';
$query = http_build_query(array('format' => 'xyz', 'value' => '123'), '', $separator);
var_dump($query);
parse_str_separator($query, $arr, $separator);
var_dump($arr);
$separator = ';';
$query = http_build_query(array('format' => 'xyz', 'value' => '123'), '', $separator);
var_dump($query);
parse_str_separator($query, $arr, $separator);
var_dump($arr);
$separator = '-';
$query = http_build_query(array('format' => 'xyz', 'value' => '123'), '', $separator);
var_dump($query);
parse_str_separator($query, $arr, $separator);
var_dump($arr);
$separator = ',';
$query = http_build_query(array('format' => 'xyz', 'value' => '123'), '', $separator);
var_dump($query);
parse_str_separator($query, $arr, $separator);
var_dump($arr);
string(20) "format=xyz&value=123"
array(2) {
["format"]=>
string(3) "xyz"
["value"]=>
string(3) "123"
}
string(20) "format=xyz value=123"
array(2) {
["format"]=>
string(3) "xyz"
["value"]=>
string(3) "123"
}
string(20) "format=xyz;value=123"
array(2) {
["format"]=>
string(3) "xyz"
["value"]=>
string(3) "123"
}
string(20) "format=xyz-value=123"
array(2) {
["format"]=>
string(3) "xyz"
["value"]=>
string(3) "123"
}
string(20) "format=xyz,value=123"
array(2) {
["format"]=>
string(3) "xyz"
["value"]=>
string(3) "123"
}
See also https://github.com/XaminProject/handlebars.php/issues/68 for a broader perspective on these syntaxes and even more alternate syntaxes.
@jslegers, you forgot one important thing. Neither of the following constructions
{{#SomeHelper format=xyz&value=123}}
{{#SomeHelper format=xyz value=123}}
{{#SomeHelper format=xyz;value=123}}
{{#SomeHelper format=xyz,value=123}}
{{#SomeHelper format=xyz-value=123}}
are supported by Handlebars.js. The way it uses for complex arguments is described here: http://handlebarsjs.com/block_helpers.html#hash-arguments
@JustBlackBird :
Neither of the following constructions are supported by Handlebars.js.
Good point. I didn't realize Handlebars.js
already supported the syntax nav id="nav-bar" class="top"
The way it uses for complex arguments is described here: http://handlebarsjs.com/block_helpers.html#hash-arguments
There are some limitations to this syntax, though, which I addressed at https://github.com/XaminProject/handlebars.php/issues/68. Nevertheless, I guess it's better to address this to the Handlebars.js
support team as the XaminProject/handlebars.php
is essentially still just a PHP port of Handlebars.js
.
It's implemented by #75, so I'm closing this one.
I like to use my helpers like this:
{{#SomeHelper format="xyz" value="123"}}
but... there is not convenient way to access these values... until now ;)
$args = $template->parseTagAttributes($args);