Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9203113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:24:03+00:00 2026-06-17T23:24:03+00:00

I am retrieving a smarty array ‘data’ and I want to store it inside

  • 0

I am retrieving a smarty array ‘data’ and I want to store it inside a javascript variable ‘store’ :

{if isset({$data})}
        <script type="text/javascript">
            var store = {ldelim}{rdelim};
            {foreach from=$data key=k item=v}
                var index = {$k};
                store.index = {$v};
            {/foreach}
                alert(store);
        </script>
    {/if}

but I have no alert output. Someone could help ?

Rmk : I need that to run this

$("input").each(function(index) {
                    return this.value = store.index;
                });

Edit : Inthe source code, I get var store = {};

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:24:04+00:00Added an answer on June 17, 2026 at 11:24 pm

    Instead of going the long and very hard to read way of trying to create a javascript object/array via Smarty, try this;

    $arr = json_encode(array(array('key1' => 'value1'), array('key2' => 'value2')));
    $smarty->assign('data', $arr);
    

    and in the template;

    <script>
    var store = {$data};
    </script>
    

    So, we are letting PHP create a valid javascript object for us and assign that string to smarty, which simply created a variable and assigns that string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am retrieving an array values from database which save multi dimensional array..i want
Retrieving data from the REST Server works well, but if I want to post
When retrieving data from MySQL, the PHP array output has both numeric and name
Im retrieving a Json dataset and need to build a javascript array called 'arrProducts'.
im retrieving the Array of JSON data and trying to diplay and access it.But
I'm retrieving data from a MySQL table and displaying it on a webpage using
I'm sending and retrieving data to view it in a <textarea> . sending: $.ajax({
I tried retrieving the user's data based on the logged in UserId, but no
I'm retrieving an ArrayBuffer over XHR and want to save it to the FileSystem
I retrieving data from a csv/txt file using oledb driver ConnString = Provider=Microsoft.Jet.OleDb.4.0; Data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.