-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prerendered attributes #19
Comments
It can be done via &attributes(attributes) or with doctype html
html
head
...
<body !{bodyAttributes}>
...
</body> There is no native-like Jade implementation for PHP's |
This is true if $attributes would be an array, but in my case (a Drupal template) $attributes is just a string of rendered attributes (in Drupal theming loop). From my observations a construct: body(class=class, attributes) generates the code: <body attributes<?php attr_class($body_classes) ?>></body> So it seems the resolution could be probably as simple as
Then we would get: <body <?php print $attributes?><?php attr_class($body_classes) ?>></body> |
That would introduce Jade incompatibility. |
Added example test in 7a607f8. |
Ok, then let's go anther way. The First shot (my modifications are commented with function attrs() {
$args = func_get_args();
$attrs = array();
// $rendered_attrs = array();
foreach ($args as $arg) {
// if (is_array($arg)) {
foreach ($arg as $key => $value) {
if ($key == 'class') {
if (!isset($attrs[$key])) $attrs[$key] = array();
$attrs[$key] = array_merge($attrs[$key], is_array($value) ? $value : explode(' ', $value));
}
else {
$attrs[$key] = $value;
}
}
// }
// elseif (is_string($arg)) {
// $rendered_attrs[] = $arg;
// }
}
foreach ($attrs as $key => $value) {
if ($key == 'class') {
attr_class($value);
} else {
attr($key, $value);
}
}
// foreach ($rendered_attrs as $attrs) {
// echo " $attrs";
// }
} Now it is possible to set attributes in several ways: Using fully rendered attributes: Using array (as before): Using both: |
Possible bug. This snippet: body(class=classes)&attributes(attributes) generates erroneous PHP: <body<?php attrs(array("class" => $jade_interp = array(true), $jade->joinClasses(array($classes)->map($jade->joinClasses)->map(function ($cls, $i) use (&$jade_interp) {
return ($jade_interp[$i]) ? htmlspecialchars($cls) : $cls; }
));), $attributes); ?>>
</body> |
That behavior IS a bug and is non-implemented part of Compiler.attrs method. Unfortunately, I can't figure out how to fix quickly, so leaving it into background. |
I need to generate this PHP output:
which seems currently impossible to achieve with canonical jade syntax, so I used this workaround as a temporarily solution:
Ideas?
The text was updated successfully, but these errors were encountered: