Post by vreyesim » Tue Jan 09, 2024 5:14 am

hello,

i try to convert twig to tpl be able to use 3,0,0 payment extension in 2,3,0. using a convertor, convert most of it. compare the files and folders, they are same.

in converted tpl i have 2, 3 lines more which aren't converted.

twig lines

Code: Select all

<select name="payment_special_mode" class="form-control">
              <option value="1" {{ payment_special_mode? 'selected' : '' }}>{{ text_enabled }}</option>
              <option value="0" {{ payment_special_mode? '' : 'selected' }}>{{ text_disabled }}</option>
</select>
to tpl lines

Code: Select all

<select name="payment_special_mode" class="form-control">
       <?php if ($payment_special_mode) { ?>
       <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
       <option value="0"><?php echo $text_disabled; ?></option>
       <?php } else { ?>
       <option value="1"><?php echo $text_enabled; ?></option>
       <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
       <?php } ?>
  </select>
is this correct?

New member

Posts

Joined
Sun Jan 28, 2018 2:34 am

Post by vreyesim » Tue Jan 09, 2024 5:55 am

i also changed user_token to token,
$data['token'] = $this->session->data['token']

New member

Posts

Joined
Sun Jan 28, 2018 2:34 am

Post by carolhunter34 » Wed Feb 14, 2024 4:55 pm

I’m glad to hear that you are trying to convert twig to tpl to use a newer payment extension in an older OpenCart version. It sounds like you have used a converter tool to do most of the conversion, but you are not sure if the result is correct.
Based on the web search results, your conversion of the twig lines to the tpl lines seems to be correct. You have used the PHP if-else statement to check the value of the payment_special_mode variable and echo the text_enabled or text_disabled accordingly. This is equivalent to the twig ternary operator that uses the question mark and the colon. Ball Sports Gear
However, you should be aware that converting twig to tpl may not be enough to make the payment extension work in OpenCart 2.3.0.2. There may be other compatibility issues or dependencies that you need to consider. You should also test the extension thoroughly before using it on a live site.
If you need more help with converting twig to tpl, you can use some online tools that can do the conversion for you, such as Twig to TPL Online Converter or TWIG to TPL converter. You can also check some online tutorials or forums that explain how to do the conversion manually, such as Twig file to Tpl conversion of opencart or convert twig to tpl. I hope this helps you convert twig to tpl for your OpenCart project
Last edited by carolhunter34 on Thu Feb 15, 2024 1:01 pm, edited 3 times in total.

Newbie

Posts

Joined
Wed Feb 14, 2024 4:37 pm

Post by OSWorX » Wed Feb 14, 2024 10:36 pm

Code: Select all

<select name="payment_special_mode" class="form-control">
       <?php if ($payment_special_mode) { ?>
       <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
       <option value="0"><?php echo $text_disabled; ?></option>
       <?php } else { ?>
       <option value="1"><?php echo $text_enabled; ?></option>
       <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
       <?php } ?>
  </select>
can be simplified to this:

Code: Select all

<select name="payment_special_mode" class="form-control">
  <option value="1"<?php echo $payment_special_mode == '1' ? ' checked="checked"' : ''; ?><?php echo $text_enabled; ?></option>
  <option value="0"<?php echo $payment_special_mode == '0' ? ' checked="checked"' : ''; ?><?php echo $text_disabled; ?></option>
</select>
or

Code: Select all

<select name="payment_special_mode" class="form-control">
  <option value="1"<?php echo $payment_special_mode ? ' checked' : ''; ?><?php echo $text_enabled; ?></option>
  <option value="0"<?php echo !$payment_special_mode ? ' checked' : ''; ?><?php echo $text_disabled; ?></option>
</select>
Coding like this is called using a "ternary operator".
2nd variation is more "up to date" .. saves a lot of space if applied to hundreds of templates .. and is easier to read ..

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: No registered users and 6 guests