JS get PHP (ecshop smarty Template) array element value, how to solve

Source: Internet
Author: User
Tags smarty template
JS get PHP (ecshop smarty Template) array element values
Recently modified PHP Things (Ecshop), encountered a problem, sincere help you master:
1. On the PHP page, use the Smarty template to assign a value, some of the code is as follows:

while ($row = $db->fetchrow ($res))
{
if ($cur ==null)
$cur = $row [' template_id '];
$modelrow [$row [' template_id ']]= $row [' template_id '];
$modelcontent [$row [' template_id ']]=trim ($row [' template_content ']);
$modelplates [$row [' template_id ']]= $row [' Template_subject ']. "-$row [content_category]-". $row [' Template_subject_ Second '];
echo $modelcontent [$row [' template_id '];

}
$smarty->assign (' cur ', $cur);
$smarty->assign (' Modelrow ', $modelrow);
$smarty->assign (' modelplates ', $modelplates);
$smarty->assign (' modelcontent ', $modelcontent);
/*end*/

$modelcontent array passed to the foreground in the DWT template in the JS function:
1, display gets a variable value temp=$ ("#temp"). Val (); (The value of this variable is 1, 2, 3, etc., get no problem.) )
2. var a= ' {$modelcontent. temp} '; The second step uses the variable to get an element value of $modelcontent, but it is empty, and I don't know how to get it; var a= ' {$modelcontent. 1} ' at the time of the test Gets whether the array is labeled 1 or can be obtained.
Now the question is how to get the array corresponding subscript value based on the known variable? There are other solutions, thank you! Ecshop Smarty PHP

Share to:


------Solution--------------------
Into
var a= ' ';
alert (a); look at the results.
------Solution--------------------
var a= ' {$modelcontent. ' +temp+ '} ';
alert (a);
So try again.
------Solution--------------------
Http://www.zui88.com/blog/view-261.html
See if it's going to help you.

References
in the Smarty template, the key name of the array is the value of a variable, and how to display the value corresponding to the key name
In: Back-end Program
The topic is a bit around the mouth, probably means

PHP has been assigned to a template array with the following information:

$config = Array (

1=> ' Zhongshan ',

2=> ' Stone qi '

);

The field in the database storage area records the key name of the array, such as 1, which is now displayed on the template: Zhongshan.

If this is the case, the error is:

{{$config. $row. Region}}

The correct wording on the stencil is: {{$config [$row. Region]}}

The problems encountered today are even more complicated, as database fields store some of the configuration serialization, so you need to do the deserialization when you pick up the region information, and there must be an assignment process in between:

{{Assign Var=param value= $l. Params
------Solution--------------------
Unserialize}}

And then $param.region can get 1 of that value.



------Solution--------------------
{lection} When there is no key???

It's either a mass transfer or a column of storage keys.
------Solution--------------------
Does the Smarty cycle work? I'm talking about an array of loops. There's a key column. When you conveniently use the array
I just wrote it wrong.
{section Name=loop loop= $v}
{$v [loop]. Array key Value}
{/section}

You print the key to see if the key is the other number causes the key to not take the correct value
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.