Redirect From .tpl

Which is the best way to automatically redirect from tpl file… ?



Or, does cs-cart/bootstrap have “built-in” function for this?


<br />
{if empty($my_var)}<br />
    redirect to domain://index.php?dispatch=checkout.checkout&edit_step=step_two<br />
{/if}<br />

[quote name='gabbo' timestamp='1397020960' post='181323']

Which is the best way to automatically redirect from tpl file… ?



Or, does cs-cart/bootstrap have “built-in” function for this?



{if empty($my_var)}
redirect to domain://index.php?dispatch=checkout.checkout&edit_step=step_two
{/if}


[/quote]



Try:


```php

{if !$my_var}


{/if}

```



Hope that helps.

Works GREAT… but now I want to extend it to prepare for cs seo function :-)



How do I change java to accept this kind of url?


<br />
"{"`$url`?dispatch=checkout.checkout&edit_step=step_two"|fn_url}"<br />

```php

{if !$my_var}


{/if}

```



But I don't think there is an SEO name for the various steps in checkout nor for checkout.checkout. But if there is, the above will pick it up.

[quote name='tbirnseth' timestamp='1397104845' post='181419'] {if !$my_var} {/if} But I don't think there is an SEO name for the various steps in checkout nor for checkout.checkout. But if there is, the above will pick it up. [/quote]



I think that it should create the following URL: http:// domain.com/checkout?edit_step=step_two If yes, it will work correctly.

Thanx all,



It works great, fn_url function takes cares of “seo/custom name”…

However… there are one problem…



Create redirect

[i][i]```php


```[/i][/i]



Redirects to…

http://domain.com/checkout?edit_step=step_two[b]&[/b]all=Y



But I can't grab redirected page in step_two (if I replace '&' to '&' in url it works).


{if !$my_var || $_REQUEST['all'] == 'Y'}


{/if}




Take a look at $_REQUEST


$_REQUEST Smarty_Variable Object (3)
->value = Array (5)
edit_step => "step_two"
all => "Y"
sl => ""
dispatch => "checkout.checkout"
object_id => "0"
->nocache = false
->scope = "tygh:addons/my_changes/overrides/view..."

Solved, put all “&” outside fn_url.



self.location = '{"index.php?dispatch=checkout.checkout"|fn_url}?edit_step=step_two{if $settings.General.checkout_style != "multi_page"}&from_step=step_four{/if}&all=Y';

This works great on both multi-page and one-page checkout, now I want to improve it, if it’s possible :-)



Is there any way to make an automatic “ajax” redirect to &step_two (when != “multi_page”)?



This url works, but it’s not automatic

<br />
{if $my_variable}<br />
    <div class="address-switch clearfix" style="margin:10px 0 -22px;"><br />
	    <div class="float-left"><br />
		    <a class="{if $settings.General.checkout_style != "multi_page"}cm-ajax{/if}" href="{"checkout.checkout?edit_step=step_two{if $settings.General.checkout_style != "multi_page"}&from_step=four{/if}&all=Y"|fn_url}"{if $settings.General.checkout_style != "multi_page"} data-ca-target-id="checkout_*"{/if}><span class="control-group">{__("change_billing_and_shipping")}</span></a><br />
	    </div><br />
    </div><br />
{/if}<br />

Why are you wanting to do this from the presentation layer (tpl) versus the business layer (php)? Seems like you are making things much more complicated than they need to be and the “business decision” about whether to redirect or not is way too late in the process.

[quote name='tbirnseth' timestamp='1397445197' post='181657']

Why are you wanting to do this from the presentation layer (tpl) versus the business layer (php)? Seems like you are making things much more complicated than they need to be and the “business decision” about whether to redirect or not is way too late in the process.

[/quote]



Can't explain in english, pm'ed you a url, test and you'll understand… I think.