Meddysong Posted June 8, 2016 Posted June 8, 2016 I have a multilingual site and one of the tricks I do to pull in language-specific blocks and images is to name them with the first two letters of the locale appended. For example, "my-image-en.png" and "my-image-eo.png". Then what I do is have a variable which will generate "en" or "eo" depending on the locale in use: {{$lingvo = substr(\IPS\Member::loggedIn()->language()->short, 0, 2);}} All i have to do after that is place {block="course-attendance-{$lingvo}"} or <img src='{setting="base_url"}uploads/assets/my-image-{$lingvo}.png' > in my templates and WHAM!, language-specific content. My challenge, having somehow managed to plug this all together, is that I'm a total novice. What I'm having to do is create $lingvo every time I want to do this trick. What I'd like to do instead is have $lingvo already existing within the system, kind of like a global variable, except that it's evaluated whenever the language changes or, presumably easier, whenever the page loads. I haven't got a clue where to do this. Part of me is saying "stick it in the globalTemplate". Is there a better approach for me to take?
TAMAN Posted June 9, 2016 Posted June 9, 2016 Thats a good trick man thanks for sharing using $lingvo variable in globalTemplate directly is the best option
Meddysong Posted June 17, 2016 Author Posted June 17, 2016 Answering my own question, since Marcher explained it to me: Adding the variable to globalTemplate is the solution but it needs to have global scope, otherwise it won't be picked up when used in other templates. To do this, the code in globalTemplate should be adjusted to {{\IPS\Settings::i()->lingvo = substr(\IPS\Member::loggedIn()->language()->short, 0, 2);}} Then if you want to call, say, a language-specific image in the footer (which is a separate template), it works perfectly.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.