JS get PHP (ecshop smarty Template) array element values

Source: Internet
Author: User
Ecshop smarty PHP

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!


Reply to discussion (solution)

Into
var a= ' ;
alert (a); look at the results.

Into
var a= ' ;
alert (a); look at the results.
This display value is also empty, in the browser below the view PHP has: Var a= ';

var a= ' {$modelcontent. ' +temp+ '} ';
alert (a);
So try again.

var a= ' {$modelcontent. ' +temp+ '} ';
alert (a);
So try again the same as the null value,

Http://www.zui88.com/blog/view-261.html
See if it's going to help you.

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|unserialize}}

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

{lection} When there is no key???

It's either a mass transfer or a column of storage keys.

{lection} When there is no key???

It's either a mass transfer or a list of stored keys. PHP and Smarty First Contact, please detailed advice, thank you

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

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 it is a key other than the number caused by key can not get the correct value of the DWT template how to use the section tag? Do you need any references or other modifications to use section?

Waiting for help

Thank you for your help! has been resolved on its own.

  • 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.