XF 2.3 Best way to color the background?

Robert9

Well-known member
We have nodes under parent_node == 17 where the background should be red.

Until now, the customer used a second style specifically for these nodes.

What is the simplest way to change the background color for all nodes with parent_node == 17?

Is there a trick with style properties? (I haven’t worked with them and know nothing about them.)

Should I modify the template to replace/add CSS?

Should I set up a separate CSS in extra.less?

I don’t want to add a new field to nodes/forums.

Any other ideas?

This is a one-time change, so nothing special is needed for regularly modifications.

Thank you.
 
Last edited:
Add this to your extra.less template, replacing 'X' with the node ID

Code:
.node.node--idX .node-body {
    background-color: red;
}

Without access to your site I can't be more precise as none of my forums have children, my categories have siblings instead. If that doesn't work as expected, give me a link to your site and the name of the forum you want the background changed.
 
Yes, i could do, but then I would have a really, really long list.
I would choose this for two or three nodes.

Instead, I would prefer a template mod like:

if ($node.parent_node == '17')


My question is, what is the lightest way to do it for all nodes with parent_node == 17;
 
What you want there is classed as a conditional statement, and I'm not sure if you can use that to implement a styling class - it may be possible, but that's beyond me. Again, seeing your site and the part you want changed would be helpful as I could use the browser console to try some class adjustments, without getting hands on it's not a simple task. There are shortcuts to reduce the number of lines, but I would need to see your site.

The second post in this section (a sticky) explains that a link to the site is essential for any class changing work to be tested, otherwise it's like trying to shoot a moving target in the dark.

 
Please don’t take it personally, but all the extra details aren’t necessary for my question. Whether I show you one page or all 24 forums I manage for clients, it doesn’t change the core issue.

All forums with parent_node == 17 should have a red background.

Some possible solutions are:
  1. Defining it using the node_id in extra.less.
    => A good solution for two or three nodes, but not for 50.

  2. Adding a condition in a Template Modification, possibly in the Page-Container, like: if node.parent_node == 17, then add the CSS class “paint_it_red”.

  3. Adding an extra field in the forum table and querying it,
    => which would be unnecessary since parent_node is already a simple and precise identifier.

  4. Creating a second style and assigning it as needed.
    => I don't think that’s particularly resource-efficient.

  5. Are there any tricks with style properties?
Is there a smarter solution for setting the background color to red for all node.parent_id == 17 than what I’ve already described?
 
Why am I concerned about this? All Xenforo pages have to go through PAGE_CONTAINER. I want to check whether we are on a node where parent_node == 17. This check really only belongs on node pages, but if I include it in PAGE_CONTAINER, then it adds an extra condition check for every existing page in Xenforo, right? I would then have to check if parent_node exists and whether it equals 17. So, I don't like that.

How else could I approach it? Should I, for example, add the check only in the relevant templates and then define a CSS rule with !important, which hopefully takes effect at the top with body color = xyz?
 
For the infosystem i can choose:

<select name="page_criteria[nodes][data][node_ids][]" multiple="multiple" class="input">

I will try to find the code behind ...
 
Back
Top Bottom