Skip to content
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

:after not working for attributes #167

Closed
bjoern-tantau opened this issue Aug 18, 2017 · 5 comments
Closed

:after not working for attributes #167

bjoern-tantau opened this issue Aug 18, 2017 · 5 comments

Comments

@bjoern-tantau
Copy link

I would like to append to the class attribute, but the previous content is overwritten.

$data = new stdclass;
$xml = '<h1 class="foo">Example Title</h1>';
$tss = 'h1:attr(class):after {content: " AFTER";}';
$template = new \Transphporm\Builder($xml, $tss);
echo $template->output($data)->body;

Expected output:
<h1 class="foo AFTER">Example Title</h1>

Given output:
<h1 class=" AFTER">Example Title</h1>

Alternatively it could be useful to be able to reference the current content of a selected element itself. Maybe with
h1:attr(class) {content: content(), " AFTER";}

@TRPB
Copy link
Member

TRPB commented Aug 18, 2017

Yes, you can do this but with a slightly different syntax. You can read the current value for the class attribute and concatenate it:

h1:attr(class) {content: attr(class), " AFTER"; }

But yes, perhaps this would be a useful addition

@bjoern-tantau
Copy link
Author

Strange, attr(class) isn't working in my particular case, but it does work in the test case. I'll investigate further.

@bjoern-tantau
Copy link
Author

It doesn't work if $data is passed in as an array.

$data = ['class' => ' AFTER'];
$xml = '<h1 class="foo">Example Title</h1>';
$tss = 'h1:attr(class) {content: attr(class), data(class); }';
$template = new \Transphporm\Builder($xml, $tss);
echo $template->output($data)->body;

@solleer
Copy link
Collaborator

solleer commented Oct 28, 2017

These tests pass fine for me:

public function testConcatDataAndAttr() {
    $data = ['class' => ' AFTER'];
    $xml = '<h1 class="foo">Example Title</h1>';
    $tss = 'h1:attr(class) {content: attr(class) + data(class); }';
    $template = new \Transphporm\Builder($xml, $tss);

    $this->assertEquals($this->stripTabs('<h1 class="foo AFTER">Example Title</h1>'),
		$this->stripTabs($template->output($data)->body));
}

public function testConcatDataAndAttr2() {
    $data = ['class' => ' AFTER'];
    $xml = '<h1 class="foo">Example Title</h1>';
    $tss = 'h1:attr(class) {content: attr(class), data(class); }';
    $template = new \Transphporm\Builder($xml, $tss);

    $this->assertEquals($this->stripTabs('<h1 class="foo AFTER">Example Title</h1>'),
		$this->stripTabs($template->output($data)->body));
}

TRPB added a commit that referenced this issue Dec 8, 2017
TRPB added a commit that referenced this issue Dec 8, 2017
@TRPB
Copy link
Member

TRPB commented Dec 8, 2017

This was fixed in the master branch, the current release supports the workaround using concatenation and the master branch and next release will support the syntax you described in the first post:

h1:attr(class):after {content: data(class); }

@TRPB TRPB closed this as completed Dec 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants