Post by Joe1234 » Thu Aug 29, 2024 12:00 am

Is it possible to get the values of the language file into the controller instead of writing text? Ex, in the controller for a parameter value put {{ something }} so it matches up with something that's in the twig and stays consistent in case I change it. How?
Last edited by Joe1234 on Fri Aug 30, 2024 9:52 pm, edited 1 time in total.

v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by by mona » Thu Aug 29, 2024 3:16 am

Code: Select all

$data['something'] = 'something';

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by Joe1234 » Thu Aug 29, 2024 4:59 am

No, that's how I get the text to the twig (or maybe I'm just not seeing what you're doing). I'm saying I want to use the same text in the controller for a parameter. Ex:

Code: Select all

function({{ something }});
The parameter is the same as the text on the front end, so I was wondering if I could use the same language code within the controller in case I ever change the text that will appear on the front end for some reason, I don't have to go in and change that piece of text in the controller. Can I use {{ something }} in the controller?

v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by by mona » Thu Aug 29, 2024 7:23 am

I believe that is correct logic for what you are after. You set the language in the controller.
To expand on that logic there are variations like -

Code: Select all

$data['something'] = $this->language->get('text_something');

Code: Select all

$something = $this->language->get('text_something');
What you have come back with is the same but working the other way around. I suspect there is something more to the question.
You can not use twig in the controller and you can not send twig back to the controller. If that is what you are looking to do, you would need to look at a more creative approach and/or ajax / javascript.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by Joe1234 » Thu Aug 29, 2024 7:50 pm

OK, if I'm understanding what you're saying here, in the controller I would do

Code: Select all

$this->load->language('language.');
$something = $this->language->get('text_something');

public function ($something ) {
-----------
}
I'll try it as soon as I get a chance. Thanks.

v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by by mona » Thu Aug 29, 2024 9:01 pm

I do not think you will be able to call a public function using a variable, but you can try ..

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by Joe1234 » Fri Aug 30, 2024 12:48 am

lol, I see how that looks. In that example "function" was actually meant to be the name of the function, then I'm so used to putting public whenever I see the word function with OC I just threw in the "public" not thinking how it looked. But no, I wont be calling the function with a variable. I'll report back with how the language thing worked out.

v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by Joe1234 » Fri Aug 30, 2024 9:51 pm

Works perfectly, thanks.

v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am
Who is online

Users browsing this forum: Gpli, nonnedelectari and 30 guests