Score:0

Unable to add custom css from asset injector module to content type

gu flag

I have a content type called Advertisement on my Drupal site. I want to add some custom css functionality to this content type (as in, when I create an advertisement from the "Add Content" button, it should have the css I want).

I am using the Asset injector module to insert the css. Here is what it looks like: enter image description here

These are the conditions I have specified in the injector:

enter image description here

However, if I try to create an advertisement, my css changes do not get reflected. enter image description here

Would anyone happen to know why the asset injector module isn't injecting my css? I've tried clearing the cache but that did not do the trick.

id flag
Have you ensured asset injector has added a reference to that CSS in a generated file into the page header on the given page?
taggartJ avatar
cn flag
stupid question but are you sure the content type is advertisement_link_class_ looks like there is an extra "_"
Shane avatar
gu flag
@taggartJ The content type is advertisement link class. Those underscores are just the machine name of the content type.
Shane avatar
gu flag
@cilefen Sorry, I don't quite understand what you mean by that. If you mean that the Preprocess CSS field for the injector has been checked, then, yes, it has been enabled.
id flag
I am asking if asset injector has actually inserted a reference to your CSS onto those pages. The CSS you wrote may not be working for other reasons.
Shane avatar
gu flag
@cilefen Nope, asset injector hasn't done that. There is no reference to my css on the page.
id flag
To be clear, you should not see the CSS in the HTML. You should see a reference to a file. https://drupal.stackexchange.com/questions/314102/why-dont-i-see-asset-injector-code-directly-in-the-html discusses that.
Shane avatar
gu flag
@cilefen Yup, there is a reference to a file in the head tag for the asset injector
id flag
Does that file contain your CSS?
Shane avatar
gu flag
@cilefen Yup, it does
id flag
Then I think this is a CSS question. The answer to this question as written is that yes, asset injector added your code.
Shane avatar
gu flag
@cilefen So, would you happen to know why the css did not work if asset injector did successfully inject the code?
Score:0
mx flag

Usually, there are 2 themes being used on a Drupal site, one for the "public" side (default theme), and the other for "backend" content (admin theme). You have to figure out which theme you want your custom CSS to be added to.

In your question, the screenshot is showing a page through which new content is being added, and it seems by its design that the theme being used is one of the admin themes.

You are probably using the option Use the administration theme when editing or creating content. You can find that option on the Administration > Appearance page /admin/appearance.

Asset Injector is most likely adding the CSS to the default theme, not the admin theme.

In your case you can turn off the mentioned option. This way you will see the default theme when creating new content, and get the custom CSS, but you may not be happy with the look of other elements on the page, depending on the form styles in your default theme.

Or you can check if Asset Injector has the option which theme to add the CSS to. If you can make it add to the admin theme you can continue to use the admin theme for creating/editing content.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.