user3342042
user3342042

Reputation: 241

Smarty variable inside Jquery code issue?

When I put SMARTY variable between {literal}{$txt_more}{/literal} in Jquery then in source code it display right text (více without quotes) but in console it show this error: ReferenceError: v\u00EDce is not defined - this error I thought is because it is not in quotes but when I put it into quotes {literal}'{$txt_more}'{/literal} it show in source code as 'více' but not display as text between tags strong with class show_text (tags are empty inside). Can you help me ? Thank you very much.

Jquery with SMARTY:

$('.show_text').text({/literal}'{$txt_more}'{literal}); // verison with quotes is without error but still not display text between tags with class show_text

$('.show_text').text('show more'); // with show more typed it displays as it should on website

HTML:

<a href="#">
  <strong class="show_text" style=" margin-top: 5px; text-align:center; overflow:hidden;white-space:nowrap;position:absolute; z-index:2"></strong>
  <img style="position:relative;" class="cond-arr" src="/css/showmore.png" alt="show_more" />
</a>

Upvotes: 0

Views: 137

Answers (2)

A. Wolff
A. Wolff

Reputation: 74420

Wrong quoting, should be:

$('.show_text').text("{/literal}{$txt_more}{literal}");

Upvotes: 1

Borgtex
Borgtex

Reputation: 3245

If you're using Smarty 3, you don't need {literal} anymore, just make sure that there is always a space after any { in your code

If using smarty 2, you don't need to be so specific with literal, remember that the problem is only when there is a "{". Your code will look much cleaner with one of this solutions:

{/literal}
$('.show_text').text('{$txt_more}');
{literal}

or using a javascript variable at the start of your code and surrounding everything else with literal just to be safe

txt_more='{$txt_more}';

{literal}
...
$('.show_text').text(txt_more);
...
{/literal}

Upvotes: 0

Related Questions