0

I have smarty array in my calendar.tpl file.i'm trying to send that array in to javascript.but i dont know how to do it.

php file

public function hookDisplayCarrierExtraContent()
    {
$DeliveryWeek=new DeliveryWeek();
$resul=$DeliveryWeek->getweekday();
$this->smarty->assign(array('WeekVal' => $resul));
return $this->display(__FILE__, 'views/templates/front/calendar.tpl');
}

calendar.tpl

<div class="block_content">
{$WeekVal}
</div>

<script type="text/javascript">
var arry= // get smarty array
</script>

------Update---------

Solution for me you can get array as text in .tpl

<div id="grabMe">{$WeekVal}</div>

<script type="text/javascript">
{literal}
    var arry= $("#grabMe").text();
{/literal}
    </script>

1 Answer 1

1

You can try something like this

var arr = {$WeekVal|json_encode};
Sign up to request clarification or add additional context in comments.

5 Comments

i have tried it.then my console showing Uncaught SyntaxError: Unexpected token &
How about this ? var arr = {$WeekVal|@json_encode};
Thank you very much ` <div id="grabMe">{$testVar}</div> {literal} <script language="javascript" type="text/javascript"> var testVar = $("#grabMe").text(); </script> {/literal}` worked for me
You're welcome! Add the working code to your question. Or add an answer.

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.