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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:12:57+00:00 2026-05-29T19:12:57+00:00

I have assigned a variable based on the number of characters in a name,

  • 0

I have assigned a variable based on the number of characters in a name, which returns an integer (1,2,3, etc). I would like to further add an {if} statement to show an option if the option name matches the variable. The option names are 5″ x 7″ – 1, 5″ x 7″ – 2, 5″ x 7″ – 3 etc.

{assign var="numberofcharacters" value=$smarty.get.name|count_characters}

{if $vr.variant_name == '5" x 7" - $numberofcharacters' || $vr.variant_name == '8" x 11" - $numberofcharacters'}
...
{/if}

This is not producing a result, even though I have 3 options that should be showing. Please could somebody let me know what is wrong with my {if} statement?

I cannot use:

{if $vr.variant_name|contains:}

because if the value returned is 1, then 10, 11 and 12 are also included when I just need 1 included.

MANY THANKS

  • 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-05-29T19:12:58+00:00Added an answer on May 29, 2026 at 7:12 pm

    Smarty3 with escaped quotes:

    {$numberofcharacters = 1}
    {$var = "5\" x 7\" - {$numberofcharacters}"}
    {$var}
    

    or

    {$numberofcharacters = 1}
    {$name = '5" x 7"'}
    {$var = "{$name} - {$numberofcharacters}"}
    {$var}
    

    or Smarty2

    {assign var="numberofcharacters" value=1}
    {assign var="name" value='5" x 7"'}
    {assign var="var" value="`$name` - `$numberofcharacters`"}
    {$var}
    

    or using the cat modifier

    {assign var="numberofcharacters" value=1}
    {assign var="name" value='5" x 7"'}
    {assign var="var" value=$name|cat:" - "|cat:$numberofcharacters}
    {$var}
    

    throwing things together should be easy enough…

    {$numberofcharacters = 1}
    {$five_seven = "5\" x 7\" - {$numberofcharacters}"}
    {$eight_eleven = "8\" x 11\" - {$numberofcharacters}"}
    {if $vr.variant_name == $five_seven || $vr.variant_name == $eight_eleven}
      …
    {/if}
    

    But… If you have a fixed pattern you want to check, you might want to use a regular expression instead? or a substr?

    {$variant_name = '5" x 7" - 123'}
    {if preg_match('/^5" x 7"|^8" x 11"/', $variant_name, $tmp)}
      hello world
    {/if}
    

    (you should do stuff like that in your PHP though…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python thread, assigned to a variable name xx, which, when it
i'm wondering how can i add an integer which i have assigned in a
I have a TDateTime variable which is assigned a value at runtime of 40510.416667.
I have a string variable which is assigned with certain no. of labels. For
I have a string like this: /AuditReport It is assigned to variable rep. If
I have the contents of a web page assigned to a variable $html Here's
I have declared one variable in xslt, assigned some value to it but while
I want to have some function that would return Base if a variable of
Can variable be assigned self invoking function module so that the variable reference would
I want the following: After logging in, A user will have assigned session variable,

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.