C
C
CrewCut2016-02-13 05:19:23
PHP
CrewCut, 2016-02-13 05:19:23

How to pull out smarty variable in php code in a normal way?

This is the second time in my life I've come across Smarty, so my question may sound very stupid. Please guide me on the path of the bright side and suggest what to do:
In the smarti template file there is a code responsible for displaying the image:

{if $unit_list[i].photo_list.0.file}<a href="/images/catalog/{$unit_list[i].photo_list.0.file}" class="highslide" onclick="return hs.expand(this)"><img src="/images/catalog/small/{$unit_list[i].photo_list.0.file}" title="{$unit_list[i].tip_info.descr} {$unit_list[i].creater_info.descr} {$unit_list[i].descr}" alt="{$unit_list[i].tip_info.descr} {$unit_list[i].creater_info.descr} {$unit_list[i].descr}"/></a>
{else}
<img src="/images/no_photo.jpg" title="{$unit_list[i].tip_info.descr} {$unit_list[i].creater_info.descr} {$unit_list[i].descr}" alt="{$unit_list[i].tip_info.descr} {$unit_list[i].creater_info.descr} {$unit_list[i].descr}"/>
{/if}

A little higher, I want to use the {$unit_list[i].tip_info.descr} variable in my php code, but I can’t figure out how to drive it there. Googled - found only how to drive a php-variable into smart, but did not find it on the contrary. Maybe I'm not digging there at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-08-25
@iCoderXXI

The fact is that smart is a template engine, i.e. it is responsible for presenting (rendering) the data before returning it to the browser, and its work usually begins when the controller has already completed its work. It is for this reason that there are no direct ways to transfer something from smarty back to the code, because it is not usually needed.
And, for good, you need to adhere to this style of programming, otherwise it will turn out to be the wildest mess and it will be more and more difficult to figure out where and who changed the state, and, therefore, catching jambs and bugs, sooner or later, will become a mega-difficult task.
In general, I categorically do not recommend trying to pass something from the smarti back to the code, only if it is not a rendered template, for example, letters that are rendered before the controller completes its work. In all other cases, one-way data flow is required.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question