Open cxj opened 6 years ago
You can use div:data["x" in myArray]
which does in_array('x', $myArray)
or div:data[myArray!=""] {display: none;}
to determine whether and array is empty.
Is there some way to check for a key
in the array? in_array()
works on values only.
div:data[myArray.key1]
should work, although I haven't tested it.
edit: Though that will be the same as !empty($array['key1'])
rather than array_key_exists
.
This check for an empty array doesn't seem to work:
<?php
require "vendor/autoload.php";
$xml = '<div>This is the foo message.</div>';
$tss = 'div:data[foo!=""] { content: "condition true"; }';
$tpl = new Transphporm\Builder($xml, $tss);
$data['foo'] = [];
echo $tpl->output($data)->body . PHP_EOL;
I expected the output to be <div>This is the foo message.</div>
because array foo is empty, i.e. foo=""
. But my output is <div>condition true</div>
.
But it is true that empty array !==
empty string.
Transphporm uses != internally instead of !==
Would it be possible and desirable to add a few more conditional operators to the
:data[condition]
selectors, possibly modeling the syntax on other CSS attribute selectors? For example, I would find the following operations very helpful (chosen syntax is completely arbitrary and repurposed from CSS):key1
: