This topic is locked
[SOLVED]

Pass variable to css code

6/15/2024 8:48:25 AM
PHPRunner General questions
P
PK author

Hello All,
I use this code in the css of my login page on the Style Editor to add a background to the login page.

body.function-login {
height:100%;
background:transparent url("https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=30582&image=1&table=forumtopics");
background-size:cover;
}

It works with no problem but.
But the application will be used on-prem (not online) but different clients who will have (I assume different URL and port to the server). I I want to create a field in my database to hold the url string and image name so that I can't pass it to the ccs. I know I grab the string from the database into a session variable at AfterInit but how do I pass this on to the css code?
Or I can grad the ApplicatioPath directly and pass it to the css code.
Any ideas on how to acheive this?

Thanks
Percy

mbintex 6/16/2024

As a possible way to go:

I change accent colors in my apps with

<?php
$farbe=$_SESSION["akzentfarbe"];
$farbe2=$_SESSION["akzentfarbedunkel"];
$farbe3=$_SESSION["akzenthintergrund"];
?>
<script>
farbe = "<?php echo $farbe; ?>";
farbe2 = "<?php echo $farbe2; ?>";
farbe3 = "<?php echo $farbe3; ?>";
darkmode = "<?php echo $darkmode; ?>";
</script>

in the header file and this code in the customfunctions.js

$( document ).ready(function() {

//Akzentfarben
document.body.style.setProperty('--akzentfarbe',farbe);
document.body.style.setProperty('--akzentfarbedunkel',farbe2);

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
// dark mode
document.body.style.setProperty('--akzenthintergrund','#555555');
}
else
{
document.body.style.setProperty('--akzenthintergrund',farbe3);
}

});