Henk Z Henk Z - 1 year ago 185
Smarty Question

PHP Smarty replace

I use PHP Smarty and now I want to use

on a more correct way.

I want to remove the entire
<div class="news-text"></div>
and its inner content.

How can I achieve that?

My code currently looks like this, but it is nasty because it only hide the content:

{$announcement.text|replace:'<div class="news-text"> ':'<div style="display:none;" class="news-text">'}

Answer Source

Smarty cannot do that in a reliable way. You can try to create a custom plugin to manipulate html or better, modifiy the contents of the variable before sending it to Smarty.

Your current solution is also unnecessary and may be prone to errors. You can do it with simple css, no replace required; i.e.:


<div class="no_news_text">


.no_news_text .news-text{display:none !important;}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download