Smarty replace the string and use another variable instead of that

1.2k views Asked by At

I have a form in smarty like this

 <div class="psmd_content">
    <div class="psmd_text">
      <form class="psmd-form psmd_">
        <div class="psmd-fields">
          {if {$display_fields} == 1 || {$display_fields} == 2 }
          <input type="text" placeholder="Enter first name" name="psmd_fname" class="psmd_fname">
          {/if}
          {if {$display_fields} == 2}
          <input type="text" placeholder="Enter last name" name="psmd_lname" class="psmd_lname">
          {/if}
          <input type="text" placeholder="Enter your email" name="psmd_email" class="psmd_email">
        </div>
        <div class="psmd-btn-cont">
          <button class="psmd-btn">{$submit_button_text}</button>
        </div>
        <div class="psmd-clear"></div>
        <div class="psmd-validation"></div>
        {$popup_content}
      </form>
      <div class="psmd-clear"></div>
    </div>
  </div>

To capture this I made the code like

{capture name=PSMD_FORM}
  <div class="psmd_content">
    <div class="psmd_text">
      <form class="psmd-form psmd_">
        <div class="psmd-fields">
          {if {$display_fields} == 1 || {$display_fields} == 2 }
          <input type="text" placeholder="Enter first name" name="psmd_fname" class="psmd_fname">
          {/if}
          {if {$display_fields} == 2}
          <input type="text" placeholder="Enter last name" name="psmd_lname" class="psmd_lname">
          {/if}
          <input type="text" placeholder="Enter your email" name="psmd_email" class="psmd_email">
        </div>
        <div class="psmd-btn-cont">
          <button class="psmd-btn">{$submit_button_text}</button>
        </div>
        <div class="psmd-clear"></div>
        <div class="psmd-validation"></div>
        {$popup_content}
      </form>
      <div class="psmd-clear"></div>
    </div>
  </div>
{/capture}

and used it like this

{$smarty.capture.PSMD_FORM}

This is working fine

But I have a variable {$content} When I am just using this variable it is showing me values like this

ENTER YOUR EMAIL 
{PSMD_FORM}
know about our exclusive items, New catalogs and special promotions

Now I want to replace {PSMD_FORM} with my form. So I did like this

str_replace({PSMD_FORM}, {$smarty.capture.PSMD_FORM}, {$content}); but its not working. So can someone tell me how to rslve this? Any help and suggestions will be really appreciable. Thanks

1

There are 1 answers

0
NewUser On BEST ANSWER

This worked for me

{$popup_content|replace:'{PSMD_FORM}': {$smarty.capture.PSMD_FORM} }