title: Sugarcrm and Smarty : stripping tags.. or not?
body: <p>I'm having a bug under a sugarcrm Enterprise 6.5.16 with the Synolia Pdf Template.
  my client has set the template as follow :</p>
  
  <p>Pdf template, having this content:</p>
  
  <blockquote>
    <p>Giving you the <code>{$fields.text_courrier_c.value}</code> by this pdf now.</p>
  </blockquote>
  
  <p>So it brings me the content of the field texte_courrier_c. This field is a memo field.
  So, it is filled with html. So, basically we have this value for texte_courrier_c</p>
  
  <pre><code>&lt;p&gt;&lt;strong&gt;blablablabla&lt;/strong&gt;&lt;br/&gt;Test carriage return&lt;/p&gt;
  </code></pre>
  
  <p>But in the display, she does not want to display the html tags.
  so, she just wants to display </p>
  
  <blockquote>
    <p>Giving you the <strong>blablablabla</strong></p>
    
    <p><strong>Test carriage return</strong> by this pdf now.</p>
  </blockquote>
  
  <p>.</p>
  
  <p>this is what she made :</p>
  
  <pre><code>{$fields.text_courrier_c.value|escape:'htmlentitydecode'}
  </code></pre>
  
  <p>But, by doing this, we have a carriage return <strong>BEFORE</strong> the field's value and <strong>AFTER</strong> it, and that is not what we want.
  like this :</p>
  
  <blockquote>
    <p>Giving you the</p>
    
    <p><strong>blablablabla</strong></p>
    
    <p><strong>Test carriage return</strong></p>
    
    <p>by this pdf now.</p>
  </blockquote>
  
  <p>It is one sentence, we don't want a carriage return between the template's text and the field's value...</p>
  
  <p>I tried to use the replacement for the <p> tag, but it does not work.</p>
  
  <p>And the <code>{strip}</code> or <code>strip_tags</code> will erase every htmltag, but i can have a <code>&lt;strong&gt;</code> tag to keep somewhere in the field..</p>
  
  <p>So, to make it clear : all i want is removing the <strong>first</strong> and <strong>last</strong> tag, so i have no carriage return between teplate's text and field's value. I tried to add some <code>{php}echo str_replace('&lt;p&gt;','',{$fields.text_courrier_c.value});{/php}</code> but ir does not work, since the tag <code>&lt;p&gt;</code> is translated by smarty used for my pdf template.</p>
  
  <p>Do you have any idea on how i could achieve this?</p>
  
  <p>Thanks you a lot!</p>
  
  <p><strong>EDIT : found it :</strong>
  first of all, i made a logic_hook before_save calling the following function :</p>
  
  <pre><code>    function stripPTags(&amp;$bean, $event, $arguments=null)
    {
      if(!empty($bean-&gt;texte_courrier_c)){
          $bean-&gt;texte_courrier_c = html_entity_decode($bean-&gt;texte_courrier_c);//déjà, on encode et on décode.
          $texteStripped = strip_tags($bean-&gt;texte_courrier_c,'&lt;strong&gt;&lt;br /&gt;&lt;br&gt;&lt;span&gt;&lt;em&gt;&lt;a&gt;&lt;ol&gt;&lt;li&gt;&lt;ul&gt;&lt;address&gt;&lt;sup&gt;&lt;sub&gt;&lt;pre&gt;&lt;hr&gt;&lt;h1&gt;&lt;h2&gt;&lt;h3&gt;&lt;h4&gt;&lt;h5&gt;&lt;img&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;');//on enlève tous les &lt;p&gt;, MAIS PAS LE RESTE
          $bean-&gt;texte_courrier_c=htmlentities($texteStripped);//on re balance
          //var_dump($bean-&gt;texte_courrier_c);exit();die();
          $bean-&gt;save();//et on sauvegarde
      }                                                                                                   
    }
  </code></pre>
  
  <p>And in the PDF templates, i'm requesting texte_courrier_c content by <code>{$fields.texte_courrier_c.value|escape:'htmlentitydecode'}</code>
  It does work, even if the customer has to change his habits (like for charriage return, has to press Shift+Enter ...)</p>