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

  • SEARCH
  • Home
  • 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 8563915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:04:50+00:00 2026-06-11T17:04:50+00:00

This is the example array I get sent from the CMS to Smarty. [field]

  • 0

This is the example array I get sent from the CMS to Smarty.

[field] => Array
(
    [value] => 19
    [options] => Array
        (
            [labels] => Array
                (
                    [0] => --- Select ---
                    [1] => John
                    [2] => Mark
                    [3] => Luke
                    [4] => Philip
                )

            [values] => Array
                (
                    [0] => 
                    [1] => 15
                    [2] => 1
                    [3] => 19
                    [4] => 17
                )

        )

So I would normally write {$field.value} or {html_options values=$field.options.values output=$field.options.labels selected=$field.value}

My question is how can I easily get the label from the value. I tried this: {$field.options.labels[$field.value]} but then realise this is just going to get the index of the array and not the value.

I know you could do this in a {foreach/if} but that is going to get messy in the template. Is there a way to write a plugin for this?

  • 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-11T17:04:51+00:00Added an answer on June 11, 2026 at 5:04 pm

    Without foreach loop it can be done in one-liner:

    {$field.options.labels[$field.value|array_search:$field.options.values]}
    

    Or modifier:

    function extractLabel($field){
        $idx = array_search($field['value'], $field['options']['values']);
        if($idx !== FALSE && isset($field['options']['labels'][$idx])){
            return $field['options']['labels'][$idx];       
        }
    }
    
    $smarty->registerPlugin('modifier', 'extractLabel', 'extractLabel');
    

    tpl:

    {$field|extractLabel}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to isolate array name and array size from code. This example of
how i can duplicate one element from array: for example, i have this array:
I copied this code from an example . I've read it 100 times. Array.prototype.map
I have an array list of objects and I am using this example to
I have a PHP array which looks like this example: $array[0][0] = 'apples'; $array[0][1]
In this simple example, i want to create a String array populated with each
This is an example of a mixed, multi-level, irregular array in php: $settings['style_formats'] =
My current code is this $swift = email::connect(); $swift->setSubject('hello') ->setFrom(array('alex@example.com.au' => 'Alex')) ->setTo(array('alex@example.com.au' =>
For example i have an array like this: $test= array(0 => 412, 1 =>
I have this array, for example (the size is variable): x = [1.111, 1.122,

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.