Post by KanKan2022 » Fri Aug 19, 2022 2:30 pm

Hi, I have a controller file (for an email template extension) which I want to add a variable to the shortcodes. In the controller file, it has the following:
$productPars = array( 'special' => '{special_list}',
'bestseller' => '{bestseller_list}',
'new' => '{new_product_list}',
'selected' =>'{selected_products}');

What I would like is to add a variable (but it doesn't work this way):
$productPars = array( 'special' => '{special_list-$att}',
'bestseller' => '{bestseller_list-$att}',
'new' => '{new_product_list-$att}',
'selected' =>'{selected_products-$att}') ;
so that I could use shortcodes such as {bestseller_list-2} and in the controller use standard str_contains with switch statement etc to get the $att.
But what happens is the shortcode {bestseller_list-2} isn't accepted as a shortcode (the $att as a variable in this situation doesn't work) so in the template it contains the actual string "{bestseller_list-2}".
So I'm wondering what would be the best way to have a shortcode that is accepted as such with a variable in it?
ie {bestseller_list-2} {bestseller_list-3} {bestseller_list-1} etc all accepted as shortcodes without having to add each individually in an array.
Thanks

New member

Posts

Joined
Sat Jul 02, 2022 4:36 pm

Post by thekrotek » Fri Aug 19, 2022 5:31 pm

Just explode the shortcode by "_" and grab the last item of resulting array. Then do what you need with this number.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by KanKan2022 » Fri Aug 19, 2022 6:02 pm

Thanks, could you please explain a little for me. At the moment, this doesn't work:
$productPars = array( 'special' => '{special_list-$att}',
'bestseller' => '{bestseller_list-$att}',
'new' => '{new_product_list-$att}',
'selected' =>'{selected_products-$att}') ;
The $att isn't considered a variable within the shortcode because if I use {new_product_list-2} on the email template, then do a switch statement, case '{new_product_list-2}' doesn't exist, which I'm assuming is because I can't use the variable in the shortcode ('new' => '{new_product_list-$att}',) Instead it is passed as a string on the email template so the email gets sent out showing the text "{new_product_list-2} "

New member

Posts

Joined
Sat Jul 02, 2022 4:36 pm

Post by KanKan2022 » Sat Aug 20, 2022 1:09 pm

I ended up adding every variation of shortcode I would be using. Makes the code long and it's not what I wanted to do but it works.

New member

Posts

Joined
Sat Jul 02, 2022 4:36 pm

Post by paulfeakins » Mon Aug 22, 2022 10:31 pm

You'd need to post the full code of the controller for anyone to give you a proper answer.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom
Who is online

Users browsing this forum: Baidu [Spider] and 248 guests