You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Richard edited this page Feb 27, 2016
·
1 revision
Writing to Attributes
Unlike CSS, Transphporm selectors allow direct selection of individual attributes to set their value. This is done using the pseudo element :attr(name) which selects the attribute on the matched elements.
element:attr(id)
Will select the element's ID attribute.
Working example:
$users = [];
$user = newstdclass;
$user->name = 'Tom';
$user->email = 'tom@example.org';
$users[] = $user;
$user = newstdclass;
$user->name = 'Scott';
$user->email = 'scott@example.org';
$users[] = $user;
$xml = '<ul> <li> <h3>Name</h3> <a href="mailto:email">email</a> </li> </ul>';
$tss = ' ul li {repeat: data(users);} ul li a {content: iteration(email);} ul li a:attr(href) {content: "mailto:", iteration(email);}';
$data = ['users' => $users];
$template = new \Transphporm\Builder($xml, $tss);
echo$template->output($data)->body;
Notice this uses multiple values for the content property to concatenate the full URL with mailto.