This code displays the city:

{%$allregions[$message.region].name%} 

How to insert into this variable the text that would be: " in the city"

    1 answer 1

    Why add something to a variable if the templates are created just for the inverse problem?

     <div> <b>в</b> {%$allregions[$message.region].name%} </div> 

    update by comments

    1. If you use a certain general template for output, and you need to fix it only in one place, then just do not use this template for this particular case.
    2. If you want to use, you can transfer to the chalon extra. parameter and using if -ov to regulate the output of the add. characters.
    3. pass the output string as a template parameter,

    that is, let's say your template, let's call it, title_inc.tpl looks like this

     {%foreach from=$title_reverse item='tit' name='i'%} {%$tit.name|strip_tags%} {%if $smarty.foreach.i.last eq false %} {%$allregions[$message.region].name%} / {%/if%} {%/foreach%} 

    then connect it as follows

     {$r = "в ".$allregions[$message.region].name} {include "title_inc.tpl" rname=$r} 

    and change the template itself

     {%foreach from=$title_reverse item='tit' name='i'%} {%$tit.name|strip_tags%} {%if $smarty.foreach.i.last eq false %} {%$rname|default:%$allregions[$message.region].name%} / {%/if%} {%/foreach%} 

    There can be many variations, for example

     {include "title_inc.tpl" prefix="в "} ... {%if $smarty.foreach.i.last eq false %} {%prefix%}{%$allregions[$message.region].name%} / {%/if%} 

    This option is probably more convenient and flexible in the future.

    In general, it is not clear, of course, why do you need tags {% %} %% {% %} instead of the usual { } , IMHO complicates the readability of the code. In addition, Smarty 3, which looks more concise:

     {foreach $title_reverse as $tit} {$tit.name|strip_tags} {if !$tit@last} {$prefix}{$allregions[$message.region].name} / {/if} {/foreach} 
    • The fact is that such a code is used for the title, where the name + city is displayed, but if I insert it into the code simply “into” it is displayed everywhere. Therefore, it is necessary in this variable that I wrote above. - sander
    • {% foreach from = $ title_reverse item = 'tit' name = 'i'%} {% $ tit.name | strip_tags%} {% if $ smarty.foreach.i.last eq false%} {% $ allregions [$ message.region] .name%} / {% / if%} {% / foreach%} - sander
    • @sander updated the answer - teran
    • Didn't quite understand where to insert this code "{$ r =" into ". $ Allregions [$ message.region] .name} {include" title_inc.tpl "rname = $ r}"? - sander
    • Tell me, if you assign {% $ locale.1019%} for example and write "in" in it. Is it possible to insert into this variable? {% $ allregions [$ message.region] .name%} - sander