473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Smarty Template Array Question.

I have an application that uses an array of values as a "lookup" table and
smarty as a template engine.

$lookup['stuff']['a'] = "label";
$lookup['stuff']['b'] = "label2";
$lookup['other']['a'] = "label";
$lookup['other']['b'] = "label2";

In my application I can easily use this array to find the values I need.

$data[ $lookup['other']['b'] ];

I want to assign my lookup value to the template, and have smarty perform
the matching, but for the life of me I can't get a smarty variable to modify
itself.

{$data.$lookup.other.b} doesn't work
{$data.$lookup[other][b]} also doesn't work.

I'd also like to use these in functions like

{html_checkboxes name="id" options=$data.$lookup.other.b
selected=$data.selected }

I've searched smarty forums, but looking for an instance of "array" in the
forums it too general, and I can't find anything that points to how to do
this.

Any help is appreciated.


Jul 17 '05 #1
2 2492
Brian <ewvea3dgc7001 .@. sneakemail.com> wrote:
$lookup['stuff']['a'] = "label";
$lookup['stuff']['b'] = "label2";
$lookup['other']['a'] = "label";
$lookup['other']['b'] = "label2";

I want to assign my lookup value to the template, and have smarty perform
the matching, but for the life of me I can't get a smarty variable to modify
itself.

{$data.$lookup.other.b} doesn't work


AFAIK it's not possible, it's ambiguous. You'll have to assign
$lookup.other.b to a variable in the template.

BTW IMHO it's bad practice to do these kind of "complicated" things in a
template, you should do these things in php before handling a variable
to smarty, in smarty you shouldn't have to do more than foreach the data
and print it.

--

Daniel Tryba

Jul 17 '05 #2
In the event that someone searches for this and gets the same response I
got, here is the solution I came up with.

{assign var=temp value=$item.metalabel}
{$labels.data.$temp}

While a bit "wordy", it works.
"Brian" <ewvea3dgc7001 .@. sneakemail.com> wrote in message
news:XUOmc.45309$0H1.4262959@attbi_s54...
I have an application that uses an array of values as a "lookup" table and
smarty as a template engine.

$lookup['stuff']['a'] = "label";
$lookup['stuff']['b'] = "label2";
$lookup['other']['a'] = "label";
$lookup['other']['b'] = "label2";

In my application I can easily use this array to find the values I need.

$data[ $lookup['other']['b'] ];

I want to assign my lookup value to the template, and have smarty perform
the matching, but for the life of me I can't get a smarty variable to modify itself.

{$data.$lookup.other.b} doesn't work
{$data.$lookup[other][b]} also doesn't work.

I'd also like to use these in functions like

{html_checkboxes name="id" options=$data.$lookup.other.b
selected=$data.selected }

I've searched smarty forums, but looking for an instance of "array" in the
forums it too general, and I can't find anything that points to how to do
this.

Any help is appreciated.

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brian | last post by:
Hello, I am trying to work out how to have smarty use a string's contents as the display-> template.. ie: $smarty->display($buffer); obviously $buffer isn't a filename, but a smarty template...
2
by: Mark | last post by:
Does Smarty support assigning multidimensional arrays? I've tried to get it working, but just can't get it. can someone help me? this is what I have in my php file: $side_bar = array('link'...
2
by: Daan | last post by:
Hello all, I'm having a little problem with Smarty. Getting it to work in a simple case went fine, but now I have the following situation: / /smarty /templates template.tpl /templates_c
1
by: Richard | last post by:
I need help. I have a smarty based program that I am modifying. I have a smarty template file that consists of smarty and HTML. I need to integrate some PHP database calls into it. My problem...
1
by: Jim Red | last post by:
Hello I have a Smarty(.php.net) Question. I want to create a Navigation with a Smarty Template. How can I display an Array recursively? Do I have to write a Plugin?
2
by: Freebird | last post by:
Hello you all, =] I've a smarty var, like this: {$var} that is equal to: ttttttttttttt|zzzzzzzzzzzz It can be any size, the important is that they are separated by the '|' How do I...
0
by: Conrad | last post by:
Hi, I'm very new to Smarty Template Engine and I'm using PHP 5.0.4 on the Windows XP Professional platform and I have the following question: When I change the 7th line of the script to use a...
7
by: Man-wai Chang | last post by:
1. How could concatenate two values into a string in the template? {section name=j start=0 loop=10 step=1} {section name=k start=0 loop=10 step=1} {assign var=xx...
2
by: Gene | last post by:
i'm newcomer in using smarty and i have problem like this: i want to have one template file (e.g. index.tpl) in this file section which use variable {$content}. and two files *.php which are using...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.