How To Echo From .tpl

Anyone know how to echo from .tpl file?



This works, but apache/php writes warnings in logfile



{capture}{$my_html_var|fn_echo}{/capture}



PHP Warning: Cannot modify header information - headers already sent in Unknown on line 0, referer:

What are you trying to do that would utilize an echo? Generally you just place the template variable in the tag you want it and all is well…

Please try ```php


{capture name=“capture_name”}{$my_html_var|fn_echo}{/capture}

or<br />
```php
<br />
{$my_html_var|fn_echo}<br />

```<br />
<br />
Because we are confuse with your needs <img src="upload://7O47Vg5oKdRIES6TKXXFKIm5Kdf.png" class="bbc_emoticon" alt=":D"> you need capture or you just need to echo the $my_html_var<br />
<br />
I hope that helps,<br />
<br />
---<br />
Valentin<br />
[color=#808080][size=2]part of hungryweb.net[/size][/color]

@gabbo,



I agree with Vali and tbirnseth, it is no need to echo from .tpl file. It is already pulls all to the screen. If you type 134 there, it will be displayed on the place you type it. So, if your $my_html_var variable is a string (contains HTML code or just text) you can place it just putting the {$my_html_var} code.



But if you need debug some variable directly in .tpl file, use the following code: {$my_html_var|fn_print_r}



Hope it will be helpful for you.

[size=4]Hi,[/size]



[font=arial,helvetica,sans-serif][size=4]I must echo else it does not parse content, the $var contains “

Please check [url=“{capture} | Smarty”]Search Results for "docs" | Smarty name is missing and is required, this is the only issue in the code
{capture}{$my_html_var|fn_echo}{/capture}






Valentin

[color=#808080][size=2]part of hungryweb.net[/size][/color]

@gabbo,



Let me explain it. If you capture your variable it will never be displayed unless you specify to display it. For example the following code is right one:



{capture name="my_variable"}{$my_variable}{/capture}
{$smarty.capture.my_variable}




But if your variable contains HTML code, just add the “nofilter” parameter. E.g.



{capture name="my_variable"}{$my_variable nofilter}{/capture}
{$smarty.capture.my_variable}




In this way the content of your variable will be displayed correctly. For example please open the /design/themes/basic/templates/views/pages/view.tpl file. There you will see how the page description (with HTML code) is displayed: {$page.description nofilter}



The way you choosed (fn_echo) is completely wrong because it displays the content of your variable before the CS-Cart sent the header. That is why it brakes your store.



Hope it much clearer

Hi,



Thnx for reply, I have now tested



{capture name="my_variable"}{$my_variable nofilter}{/capture} {$smarty.capture.my_variable}




But this shows (html-tags and all) I would like to execute it…

Use the 'escape' modifier.

However, in my experience, putting html in template variables rarely works (or I should say rarely works for me).

I have nu tested all this with no luck… :-(



How could I else do?

You might attempt to use a javascript 'writeln' function call to insert the language variable data.

I.e.

```php




```
Your mileage may vary....

Tnx all, Now it's working… I don't know what i did wrong…



Register smarty var:


$view = Registry::get('view');
$view->assign('my_var', $html_content);




Show in template

```php

{$my_var nofilter}

```

But now I have a new problem, smarty-var gets lost after
```php
fn_order_placement_routines('route', $order_id, false);
```

Are there anyway to override this or must I save it in $_SESSION to still have access to it after fn_order_placement_routines?

The var should be valid for the life of the page. However, note that cs-cart ALWAYS redirects after a POST so if you're setting it in a POST context then it will be lost when the new page loads.



Where are you setting it and where does $html_content come from?

[quote name='tbirnseth' timestamp='1396060680' post='180364']

Where are you setting it and where does $html_content come from?

[/quote]



$html_content comes from payment processor response to show for user after successfull payment, and I set it in paymentprocessor on user '&mode=return' just before 'fn_order_placement_routines'



It works if I set it in $_SESSION['my_var'] and call it in template '$cart.user_data.my_var' but I can't figure out how to unset $_SESSION[my_var] from template (should only be visible once).

[quote name='gabbo' timestamp='1396068292' post='180367']

$html_content comes from payment processor response to show for user after successfull payment, and I set it in paymentprocessor on user '&mode=return' just before 'fn_order_placement_routines'



It works if I set it in $_SESSION['my_var'] and call it in template '$cart.user_data.my_var' but I can't figure out how to unset $_SESSION[my_var] from template (should only be visible once).

[/quote]

[quote name='gabbo' timestamp='1396068292' post='180367']

$html_content comes from payment processor response to show for user after successfull payment, and I set it in paymentprocessor on user '&mode=return' just before 'fn_order_placement_routines'



It works if I set it in $_SESSION['my_var'] and call it in template '$cart.user_data.my_var' but I can't figure out how to unset $_SESSION[my_var] from template (should only be visible once).

[/quote]



Sorry, $_SESSION['cart']['user_data']['my_var'], Not $_SESSION[my_var]

@gabbo,



As far as I understand, this variable should be displayed on the Order landing page. If so, you can add the post controller (e.g. checkout.post.tpl) with the following code:


if ($mode == 'complete') {
if (isset($_SESSION['cart']['user_data']['my_var'])) {
Registry::get('view')->assign('my_var', $_SESSION['cart']['user_data']['my_var']);
unset($_SESSION['cart']['user_data']['my_var']);
}
}




In this case the my_var content will be displayed just once.



Hope it will be helpful.

@eComLabs



I'll test this, I assume it should be .php file (is it possible to parse php in tpl?)



Should this file be in /controller dir or does it work to place it in under my_changes?



Is this file “checkout.post.php” parsing after user redirected in “fn_order_placement_routines” function? Or are there any other php-file I can use to make a db call after “fn_order_placement_routines” and before complete.tpl is called?

@eComLabs



YES… It works great…



I put my code it in my_changes/controllers/frontend/checkout.post.php



I have now added

use Tygh\Registry;

use Tygh\Session;



It works without them, but should they be there anyway?

Not unless you are using the Registry or Session classes. But it doesn't hurt to have the namespaces defined anyway (note: the scope of a namespace is the file it is declared in).

[quote name='tbirnseth' timestamp='1396247451' post='180483']

Not unless you are using the Registry or Session classes. But it doesn't hurt to have the namespaces defined anyway (note: the scope of a namespace is the file it is declared in).

[/quote]



Ok, then I have to let them be there, but do I have to declare anything to use db_get_field/db_query “functions” or are they always accessable?