cs cart how to pass variables through tpl files - cs-cart

in the checkout page, I am trying to pass a variable through step 2 to step 3. I want to check the town of the user and do specific payments methods according to the town of the user.
I tried a lot, but couldn't see the variable. It always returns blank!
In the step 2, (this is the page with the address and everything about the user-client) I did this:
{assign var="town" value="$user_state"}
How can I pass this variable to step 3? (file name is payment_methods.tpl)
*I read something about smarty...
I tried {php} code...
Any help? thanks in advance!

ok I found a solution to my problem.
Inside the step_profile_fields.tpl file, I have done my calculations and capture this variable, for example:
{capture name="state_of_user"}{$ship}{/capture}
In step 4, I have included the previous tpl file (step_profile_fields.tpl)
and grab this value through:
$smarty.capture.state_of_user
For example I have this:
{include file=".." user=$smarty.capture.state_of_user}
if someone need more help. please let me know!

Related

Using defined smarty variable as object key

I want to access the data of the object that comes as a smarty variable according to the variable I have defined.
I'm actually expecting like {$page->page_meta->description} as I wrote below. But nothing happens. It doesn't give an error. What is the problem?
Ok now I understand what you mean.
{foreach $metas as $meta}
{$page->page_meta->{$meta}}
{/foreach}
PS next time do not insert screenshots like this but write code

Smarty Combine internal get variable with another value

I'm trying to build a foreach loop in smarty where i have to access specific get vars like "user_1", "user_2" etc to mark checkboxes as checked. So what i need is smth like
{if $smarty.get.user_{$foreach_current_user_id} == "on"}checked{/if}
but this doesn't work.
Is there a way to pass the loop variable to the get variable? I've haven't found smth on the internet yet...
Thanks if someone knows a solution
The easiest way is to create a variable with the desired name:
{$user_name='user_'|cat:$foreach_current_user_id}
{if $smarty.get.$user_name == "on"}checked{/if}

Choosing form fields by label using Mechanize?

I originally wrote 800 lines to do this, site by site. However, on talking to a couple of people, it seems like my code is way longer than it needs to be.
So, I've got an idea of what you'd do in Python, with a particular Egg, but I'm working with Ruby. So, does anyone have any idea how to enter details in a form field, based on what the label for it is, rather than the id/name? Using Mechanize.
Let's say your html looks like:
<label>Foo</label>
<input name="foo_field">
You can get the name of the input following a specific label:
name = page.at('label[text()="Foo"] ~ *[name]')[:name]
#=> "foo_field"
and use that to set the form value
form[name] = 'bar'

Smarty assigned template variables

Looking through the Smarty debug console I discovered the variable {$u}, which contains the array video => "".
{$u} also contains photo, interview, etc. which is taken from the t1 table in the database. The database does have a url in the video column, but it is not being captured in {$u}. The problem right now is that I can't figure out where {$u} is populated.
What is the best way to find out where $u is populated?
If you can't debug your code line by line (with Zend or Xdebug), try to search your PHP code for ->assign('u', ->assign("u" or your Smarty templates for {$u=, {assign name="u", etc...
Unfortunatly there is no way to make Smarty tell you automatically where a varible was declared.

page name, or argumentless URL string in smarty?

I have a search form, and I want to create a "Start Over" link that just returns users to the page without any arguments. What Smarty code can I use? For example, if they are at http://website.com/search.php?value1=x&value2=y, I want to get http://website.com/search.php or just search.php, so I can construct <a href='{$string}'>Start Over</a>.
I would just fill a variable in your php that you send to smarty? you could get that in smarty I guess, but that's not really a good way. just do something like this:
$yourSmartyVar->assign("string",$_SERVER[’PHP_SELF’])
That should give you the scriptname without querystring if I remember correctly. If it doesn't you could use $_SERVER[’SCRIPT_NAME’] if that suits you better, or even use http://php.net/manual/en/function.parse-url.php

Resources