Jump to content

Theme Name / ID and IF Statements


Bluto

Recommended Posts

I'm posting this to get feedback and hopefully something I can use for my theme.  Here is a recap of the support request conversation.  If there is an issue posting the support ticket conversation, please remove and will type something else up.

Quote

ME

Hello.  I noticed that whatever the org template upload name is, that name will remain the same for both the below even if the Name is changed in the template settings section in Themes.


\IPS\Theme::i()->name

\IPS\Theme::i()->_title

I can understand the ->name not changing, but I would've thought that the _title would've been updated with the name change in the Theme settings.

I have a few versions of the same theme (light, dark, and blue) and trying to do an if statement I discovered that the name and _title are locked to whatever is populated in the org theme upload.

Quote

IPS

Im not sure on what you mean here. It not changing from what?

Quote

ME

When you upload a template let's call the theme name Sample_001 (whatever is populated in the xml file name="Sample_001") the name and _title are populated as Sample_001.  At this point the below would be true:


\IPS\Theme::i()->name == 'Sample_001'

\IPS\Theme::i()->_title == 'Sample_001'

If you go in and edit the theme in the (ACP > Customizations > Themes > Sample_001 >  Name) and change the name the above statements don't change.  No matter what you change the Name to in the theme editor, it always remains Sample_001 in the database but displays as the edited (changed) name in the theme settings.

This becomes an issue when someone uses a base theme and makes modifications off that base theme after it's uploaded to the site.  The theme will always be the same name.  It's impossible to create an if statement if let's say you want to use different template code in the Page's app based on what theme is being shown.  In my case, I have 2 themes based off 1 theme (light and dark) and I need to adjust what the Pages's page is displaying based on light and dark themes.

I could use ->id for each template, as suggested by another user, but this is a real pain when developing on my development server where the IDs always change because I'm uploading and testing.

Hope this explains it better.

Quote

IPS

\IPS\Theme::i()->name isn't/shouldn't be used anywhere. The name column is deprecated, it was used in IPB3 and is deprecated in IPS4. 
You also shouldn't use the title because it is a language string which can be changed. I would really suggest to use only the ID as the identifier.

Quote

ME

Hello.  Was there something besides the ID that could be used?  The problem with using ID is that the ID changes depending on where the theme is used.  If I have a bunch of if statements those would have to be changed every time I upload the theme.

Is there any way I can use the name which is set in XML file of the theme?

Quote

IPS

A theme/styles ID never changes. Could you clarify what you're exactly doing? Is it still the ongoing issue from ticket XXXXXX?
Each theme as an unique ID, so why can't you just use 


{{if \IPS\Theme::i()->id == 1}}
we're in the first theme
{{endif}}

Also, may I ask why you would want to do this at all? Why not just change the template in each theme?

Quote

ME

The ID does change across installs, whereas the name doesn't.  If I'm developing a theme on my local server and set a bunch of if statements based on ID, that ID isn't going to be the same when I install the theme from the local install to my live site.  IMO it would be less confusing tracking names then IDs especially if I have multiple themes over the 3 licenses I own.  Just being able to use the theme name and having that always the same, no matter where it was installed, would be a lot easier to use.  On my dev site I would only have to set the if statement to the name once and that would remain the same no matter where or how many times I installed it.  Whereas if I used IDs, I would have to change that multiple times:  every time I uploaded it to my dev site during testing and every time I uploaded it to a new site.  Obviously, that would require me to change the IDs for each site I installed it on and do that for the three themes I'm using for each site.  3 sites x 3 theme IDs per site = 9 total IDs I'd have to track versus 3 theme names total.

Basically it comes down to my pages APP.  If I'm, let's say, using a graphic banner on one of the pages I created and need it to be two version depending on if the user is using the light theme or the dark theme I'd need to have an if statement saying, "if light theme use dark text graphic, if dark theme use light text graphic".

Also the CSS with the pages app.  Sure, I could move all the CSS for each page I create into the theme CSS, but I'd rather keep the pages app css in the pages app and be able to use if statements to alter my pages app pages based on which theme the user has selected.  In my case, I have 3 different themes and each css needs to be different for specific elements.  The default IPS elements work fine because those are in the theme's CSS file.

I would think that having the name available to use would make sense and easier overall than using a theme ID.  Honestly, I don't want to have a chart tracking the IDs for each theme over multiple sites.

If IDs are all that's going to be available, then it is what it is.  But I hope there is some logic in my reasoning for using name vs. ID.

Quote

IPS

I see your point but as I said, the name column is deprecated, it's also not used anywhere and we'll  probably even remove the column in a future release once we start another database tables cleanup, so I would really not rely on this.

Quote

ME

Hello.  At least it's good to know not to use the name.  Maybe you could discuss internally my issue about not wanting to use the ID and provide something like another field in the theme for this specific purpose.

What would be great if I had the option to use key="123456" in the theme XML.  The key being something that wouldn't be required, but was available for people to use in specific cases like mine.  That way I could set the key in the theme XML and use that key in my if statements.

Just a suggestion.

Thanks for your time!

Quote

IPS

I would suggest to post your idea (and explanation why you need it) to our feedback forum, where our managers and other developers will be able to see it.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...