473,668 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_checkboxe s 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 2503
Brian <ewvea3dgc700 1 .@. 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 "complicate d" 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.met alabel}
{$labels.data.$ temp}

While a bit "wordy", it works.
"Brian" <ewvea3dgc700 1 .@. sneakemail.com> wrote in message
news:XUOmc.4530 9$0H1.4262959@a ttbi_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_checkboxe s 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
15474
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 inside a string variable. Take this example:
2
14061
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' => array( 'index.php', 'estate.php', 'text' => array( 'Home',
2
2900
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
2306
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 is I cannot figure out how to pass value between smarty and PHP. Going from php to smarty I've tried this: {php} $smarty = new Smarty; $smarty->assign("x", 100);
1
2299
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
4952
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 'explode' that into an array or 2 variables in the smarty template
0
1600
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 new name and refresh the browser, it maintains the old value instead of updating to the new value. Both index.php and SmartySetup.class.php appear below: index.php:
7
6204
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 value=concat($smarty.section.j,$smarty.section.k)} {xx} {/seection} {/section} 2. How could I address/use associative array in the template? I could do
2
2067
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 the same template index.tpl and only change the content. for example: /*index.php*/ $smarty = new MySmarty(); $smarty->assign('content','INDEX');
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8381
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8799
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6209
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.