Are you saying that this code does work when the song title does not contain an apostrophe?
I would be surprised when it does.
The content: line contains nested strings: the string media_title is nested inside the string {{ state_attr(config.entity, 'media_title') }}.
Like the code is now, the compiler can interpret the content: line like this:
string: {{ state_attr(config.entity,
followed by some text: media_title
followed by another string: ) }}
To have the compiler understand this correctly you have to use different types of quotation marks for the inner and the outer string.
Try this:
But this doesn’t solve the problem that when a quote or apostrophe doesn’t have a second closing element, it breaks the code when it doesn’t match a certain meta tag configuration.
A. Name of track: Track’ Title
Entity attribute:
media_title: Track' Title
1, 2 doesn’t work
ă…¤
B. Track" Title
media_title: Track" Title
3, 4 doesn’t work
ă…¤
C. Track" ’ Title
media_title: Track" ' Title
1, 2, 3, 4 doesn’t work
ă…¤
D. Track’ ’ Title
media_title: Track' ' Title
All work, but 1, 2 display Track Title , 3, 4 display Track’ ’ Title
You can use different ways to “escape” characters with a special meaning. Inside single quotes, you can put two single quotes or you could use unicode. A comprehensive sive guide can be found here:
I know about “escaping”, but I don’t understand, how I can use it with dynamic data from entity attribute which can contain different combinations of characters
I think it may be that the way templating works is messing with it here. If it is expanding the media title in there and then parsing it, then this is in essence a code injection nightmare. I also think styles should ot be used in this way to specify content too… Is there another way to get the media title displayed?
Hm… I use - platform: universal in configuration.yaml for my players. Perhaps it is worth using this code to display the player status there? But won’t the same problem arise there?