Toggle between templates based on language

More
1 year 4 months ago #155039 by taswell
taswell created the topic: Toggle between templates based on language
Hello,

I have a survey in English and French. I want to toggle between the template, to change the logo, based on which language is selected. Is that possible to do?

Please Log in or Create an account to join the conversation.

More
1 year 4 months ago #155041 by tpartner
tpartner replied the topic: Toggle between templates based on language
You should be able to do that with CSS if you give the logo images language-specific classes.

body.lang-en img.logo-fr {
	display: none;
}
 
body.lang-fr img.logo-en {
	display: none;
}

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago - 5 months 3 weeks ago #167656 by krosser
krosser replied the topic: Toggle between templates based on language

tpartner wrote: You should be able to do that with CSS if you give the logo images language-specific classes.

body.lang-en img.logo-fr {
	display: none;
}
 
body.lang-fr img.logo-en {
	display: none;
}



I need to do the same - be able to change the logo images between languages - and I can't get this code to work. Should the code differ for the LS 3.6-3.7?
I wonder why you gave the opposite languages to logos in your script? - en to fr and fr to en...

I tried it in Vanilla and Bootswatch themes.

I'm using the latest LS 3.15 hosted on LS servers, not installed locally.
Last Edit: 5 months 3 weeks ago by krosser.

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago #167659 by krosser
krosser replied the topic: Toggle between templates based on language
If anyone can help figure out how to implement the logo switch between languages, please reply.
The manual only describes how to add your own logo but has nothing on 2+ logos for one survey in different languages.

Thanks in advance!

I'm using the latest LS 3.15 hosted on LS servers, not installed locally.

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago #167688 by krosser
krosser replied the topic: Toggle between templates based on language
Tony, I've realised why you have opposite languages in the code - to hide the English logo when the page is in French and the other way round.
As I understand, I need to have both logos loaded when I run the survey in order to do so. But the theme allows to choose one logo at a time. I've tried to change the .twig file, like it's described in " Adding your own logo to the survey list (New in 3.0 ) " but changing the name of the png file in line 126 to my logo's name didn't make a difference. Perhaps, I should add the second image in the twig file?

I'm using the latest LS 3.15 hosted on LS servers, not installed locally.

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago #167690 by Joffm
Joffm replied the topic: Toggle between templates based on language
Hi, krosser,

I entered this in "navbar.twig"
{{ image('./files/myFirstImage.png', 'alt-text for my file', {"class": "logo-en"}) }}
{{ image('./files/mySecondImage', 'alt-text for my file', {"class": "logo-fr"}) }}

And it changes dynamically after changing the language by Languagechanger.




If the logo is somewhere else, other twig-file.


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The following user(s) said Thank You: LouisGac, krosser

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago - 5 months 3 weeks ago #167691 by krosser
krosser replied the topic: Toggle between templates based on language
Many thanks, Joffm, for the suggestion! I will try to reproduce what you did.
Can you please specify in which theme you did this (Fruity or Vanilla) and also in which line you added the code (any specific or at the end of the .twig)?

Also, I wonder if you just specified the logos uploaded through theme editor? Which one of them did you specify in the settings of the survey?

FYI, I'm working mostly in Bootswatch theme now, as it suits our design needs more than the others.

I'm using the latest LS 3.15 hosted on LS servers, not installed locally.
Last Edit: 5 months 3 weeks ago by krosser.

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago - 5 months 3 weeks ago #167693 by Joffm
Joffm replied the topic: Toggle between templates based on language

Can you please specify in which theme you did this (Fruity or Vanilla) and also in which line you added the code (any specific or at the end of the .twig)?

Sorry, this was in "vanilla".
I commented the original line of the brandlogo and added these two behind.
About line 35.

And it's about the same line in fruity.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last Edit: 5 months 3 weeks ago by Joffm.
The following user(s) said Thank You: krosser

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago - 5 months 3 weeks ago #167697 by krosser
krosser replied the topic: Toggle between templates based on language
So, I could reproduce what you did and make it work too - in Vanilla.
But in Bootswatch theme I cannot find where the logo is. There is no nav_bar.twig and I've searched all other twig files. What do you think I should do for this theme?

EDIT: I've just found that someone else had this issue with nav_bar.twig in Bootswatch.. although he didn't get a reply.

I'm using the latest LS 3.15 hosted on LS servers, not installed locally.
Last Edit: 5 months 3 weeks ago by krosser.

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago #167700 by Joffm
Joffm replied the topic: Toggle between templates based on language
Hi,
you only asked about "fruity" and "vanilla".

I deliberately did not write anything about "bootswatch". This seems to be something different.
I am not very successful in adapting this theme.
Therefore I stay to vanilla at the moment.

And the other thread? There was the question about the visibility of some twig files, which are visible in "fruity" but not in "bootswatch".
I think there was no answer, because nobody knows why these files are not published. (It's not a bug, it's a feature)????

Hopefully somebody extends the manual about the new theme options and theme editor.


Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago #167702 by krosser
krosser replied the topic: Toggle between templates based on language
It's okay, Joffm. I'm learning and that is why I'd like to know how it's done in all 3 default themes. Otherwise, I won't be able to do anything. So, I appreciate that you helped me figure out how it's done in Vanilla and Fruity! I can't thank you enough. :)
As my team liked Bootswatch's design more, I just wanted to stick to it and adjust to our needs.

I can see that this forum is read by the LS team members. So, perhaps, they can chime in and explain how the logo switch is done in Bootswatch...

I'm using the latest LS 3.15 hosted on LS servers, not installed locally.

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago #167704 by tpartner
tpartner replied the topic: Toggle between templates based on language
Copy nav_bar.twig to your extended theme directory (using the same file structure as that in vanilla). Then changes in that file will apply regardless of theme dependencies.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago #167705 by krosser
krosser replied the topic: Toggle between templates based on language

tpartner wrote: Copy nav_bar.twig to your extended theme directory (using the same file structure as that in vanilla). Then changes in that file will apply regardless of theme dependencies.


Do you mean I need to export both extended themes (Vanilla or Fruity and Bootswatch), then copy the header folder from Vanilla (which contains nav_bar.twig) (->views->subviews->header) into Bootswatch (into the same folder), and then import it back into the theme editor?

I'm using the latest LS 3.15 hosted on LS servers, not installed locally.

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago #167721 by tpartner
tpartner replied the topic: Toggle between templates based on language
No, you should not be doing anything with the core vanilla or bootswatch theme directories. They will be over-written on updating.

I am responding from my phone and memory this week so I may make some mistakes on the file structure but...

My understanding is that you have extended (copied) bootswatch. This should create a directory:

/upload/themes/survey/yourThemeName/

Now the theme dependency/inheritance ladder is:

- vanilla
- bootswatch
- yourThemeName


So, if you copy nav_bar.twig into...

/upload/themes/survey/yourThemeName/views/subviews/header/

...it will automatically override any copy of that file in the parent themes (bootswatch and vanilla).

You may not be able to see that new file in the template editor but any changes made in a plain-text editor and uploaded via FTP will be applied.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in or Create an account to join the conversation.

More
5 months 3 weeks ago #167722 by tpartner
tpartner replied the topic: Toggle between templates based on language
You can use an IF() statement in the twig file so only one image (depending on language) is loaded. This will reduce server load and browser load-time. I'll give an example next week when I get back to the world.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Joffm, krosser

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!