0

i put smarty code in js/jquery function but doesn't work and i see blank page! How To Fix This?

{literal}
<script type="text/javascript">
  jQuery(document).ready(function($){
      $("#IsGroupGallery").click(function() {
      {literal} {if $photos} $.lightbox(["{"\", \""|implode:$photos}"]); {/if}{/literal}
      return false;
    });

  });
</script>
{/literal}
2

2 Answers 2

2

Your inner literal tags are backwards, and you are attempting to nest additional literals inside a {literal} tag (which obviously will not work because {literal} tells Smarty to leave the contents unchanged.) It should probably look like this instead:

{literal}
<script type="text/javascript">
  jQuery(document).ready(function($){
      $("#lbgallery").click(function() {
      {/literal} {if $photos} $.lightbox(["{"\", \""|implode:$photos}"]); {/if}{literal}
      return false;
    });
  });
</script>
{/literal}

Notice the two literal tags inside your outer literal tags have been reversed. You need to first end the literal, then re-start it again, otherwise the contents of the inner {literal} tags will also be treated as literal, and not evaluated - and that just doesn't make sense for what you are trying to do :)

Sign up to request clarification or add additional context in comments.

Comments

1

Hint: Smarty3 parses { if as literal string ("auto literals"). So whenever { is surrounded by whitespace, it is ignored by Smarty3.

If that - for whatever reason - doesn't help, or you're stuck with Smarty 2, please Note that {literal} tags don't nest.

{literal}
<script type="text/javascript">
  jQuery(document).ready(function($){
      $("#lbgallery").click(function() {
{/literal}
      {if $photos} $.lightbox(["{"\", \""|implode:$photos}"]); {/if}
{literal}
      return false;
    });
  });
</script>
{/literal}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.