|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
jonal Smarty Rookie
Joined: 16 Apr 2021 Posts: 11
|
Posted: Fri Apr 16, 2021 12:29 pm Post subject: HTML with class in variable not working |
|
|
I'm pretty new to php and smarty so maybe I do something wrong.
I have this code:
Code: | {if $Data.headline_size == 'h2'}
{$selectedHeadline = "<h2 class="test">Hello</h2>"}
{else}
{/if}
<div>
{$selectedHeadline}
</div>
|
But when I use it, smarty gives me an error. Or lets say Shopware (the CMS) gives me an error that smarty crashed or something like that. Not really an error I can work with.
I tested around and for some reason this
Code: | {if $Data.headline_size == 'h2'}
{$selectedHeadline = "<h2>Hello</h2>"}
{else}
{/if}
<div>
{$selectedHeadline}
</div>
|
without the class in the h2 is working.
Why is it like this and what can I do to make it work?
Thank you very much! |
|
Back to top |
|
jonal Smarty Rookie
Joined: 16 Apr 2021 Posts: 11
|
Posted: Fri Apr 16, 2021 12:37 pm Post subject: |
|
|
Ok I tested some more and found out that if I use single quotes ' instead of " it's working.
So
Code: |
{if $Data.headline_size == 'h2'}
{$selectedHeadline = "<h2 class='test'>Hello</h2>"}
{else}
{/if}
|
Works. But I would be still interested if somebody knows why this happens. " is a normal quote for HTML syntax. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Apr 18, 2021 8:53 am Post subject: |
|
|
Because you are confusing Smarty and HTML.
Code: | {$selectedHeadline = "<h2 class="test">Hello</h2>"} | is a Smarty syntax and you must exape double quotes like in PHP:
Code: | {$selectedHeadline = "<h2 class=\"test\">Hello</h2>"} |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|