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

Add attribute with no value? #41

Closed
adjenks opened this issue Sep 1, 2016 · 3 comments
Closed

Add attribute with no value? #41

adjenks opened this issue Sep 1, 2016 · 3 comments

Comments

@adjenks
Copy link

adjenks commented Sep 1, 2016

I ran into an issue here:
<option t:for="language in languages" value="{{language['code']}}" t:attr="language['code'] == userLang ? selected='' ">{{language['name']}}</option>

How does one conditionally add a 'selected' attribute with no attribute value? Since that's how it's usually defined, by just existing, and not having any particular value.

If I use this:
t:attr="language['code'] == userLang ? selected
(no equals sign or value)
it crashes

and if I give it a null value selected=Null, it ends up giving it a zero length string in the tag like this:
selected=''

This is nit picky but I want to know if it's possible with just using Twital.

@goetas
Copy link
Owner

goetas commented Sep 2, 2016

This depends if you are in XML or HTML5 mode.
See http://twital.readthedocs.io/en/latest/api.html#basics

$twital = new TwitalLoader($loader);
$twital->addSourceAdapter('/\.wsdl$/', new XMLAdapter()); // handle .wsdl files as XML
$twital->addSourceAdapter('/\.htm$/', new HTML5Adapter()); // handle .htm files as HTML5

@goetas goetas closed this as completed Sep 4, 2016
@adjenks
Copy link
Author

adjenks commented Sep 6, 2016

I configured the source adapter to use HTML5 as you suggested. However I still receive this error if I do not add a value to the "selected" attribute:

Type: Goetas\Twital\Exception
Message: Goetas\Twital\Attribute\AttrAttribute::findAttrParts error in 'selected'
File: /var/www/commlog_dev/vendor/goetas/twital/src/Goetas/Twital/Attribute/AttrAttribute.php
Line: 108

@adjenks
Copy link
Author

adjenks commented Sep 6, 2016

This crashes: t:attr="language['code'] == userLang ? selected">
But this doesn't: t:attr="language['code'] == userLang ? selected='' ">
But I don't want the empty string.
Thank you for your time.

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

2 participants