The Joomla! Forum ™



Forum rules


Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.



Post new topic Reply to topic  [ 17 posts ] 
Author Message
PostPosted: Wed Oct 13, 2010 6:56 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Nov 07, 2009 5:06 pm
Posts: 12
Hi, I have created a Joomla template, however there is quite a few parameters that I would like the user to be able to change via the template parameters page, which affects the styling of the template.

So ideally I would like to store the css in a php file i.e. template.css.php and call this from the head of the index.php file:

index.php
Code:
<link rel='stylesheet' href="<?php echo $this->baseurl ?>/templates/mytemplatename/css/template_default.css.php" type="text/css" />


template.css.php

Code:
<?php
header('Content-type: text/css; charset: UTF-8');
?>


However this is not working. Any ideas how I can load the css file as a php file (as i really need to use the get parameters in the css file which obviously css cannot do.)

I dont want to put them into the head of the index.php as I would prefer it if the css was cached for performance reasons.

any ideas are welcome. thanks


Top
 Profile  
 
PostPosted: Thu Oct 14, 2010 8:15 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Nov 07, 2009 5:06 pm
Posts: 12
I've had a good look around online and there is nothing that seems to have any solution to this.

perhaps this is too technical for Joomla :(


Top
 Profile  
 
PostPosted: Thu Oct 14, 2010 10:10 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Nov 07, 2009 5:06 pm
Posts: 12
i've had a look at the source and I can see that the template is calling the css.php file, however, when checking the rendered source of that file it is completely blank, so for some reason it is not getting parsed properly.

any ideas anyone?!!


Top
 Profile  
 
PostPosted: Thu Oct 14, 2010 10:46 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Nov 07, 2009 5:06 pm
Posts: 12
forget it, i've solved it. thanks for all of your help! ;)


Top
 Profile  
 
PostPosted: Thu Nov 25, 2010 9:46 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Jun 15, 2008 8:49 am
Posts: 6
thanks 4 not sharing the solution >:(


Top
 Profile  
 
PostPosted: Thu Nov 25, 2010 2:48 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Jun 15, 2008 8:49 am
Posts: 6
4 all of U who got the same question...check out:
http://docs.joomla.org/Tutorial:Template_parameters
http://www.barelyfitz.com/projects/csscolor/

cheerio!


Top
 Profile  
 
PostPosted: Thu Nov 25, 2010 6:40 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Nov 07, 2009 5:06 pm
Posts: 12
the solution is way way way more complicated than my first post and by default something Joomla is not able to do.

I'm releasing a free template very soon that is built using it, so the solution will be contained in the template for anyone interested.


Top
 Profile  
 
PostPosted: Thu Dec 09, 2010 8:21 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Oct 07, 2009 8:00 pm
Posts: 17
mk5 wrote:
the solution is way way way more complicated than my first post and by default something Joomla is not able to do.

I'm releasing a free template very soon that is built using it, so the solution will be contained in the template for anyone interested.


How is the progress of your template? I have this same question and really need to know this answer.

Thank you.

Also, I read through the above links and while informative, they are not very helpful for this issue. :geek:


Top
 Profile  
 
PostPosted: Thu Dec 09, 2010 9:48 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Nov 07, 2009 5:06 pm
Posts: 12
Template is done. It will be available to download next week (in a beta form - over 400 parameters).

i'll post the link when the website is online.


Top
 Profile  
 
PostPosted: Thu Dec 09, 2010 10:22 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Oct 07, 2009 8:00 pm
Posts: 17
mk5 wrote:
Template is done. It will be available to download next week (in a beta form - over 400 parameters).

i'll post the link when the website is online.


Great news! I'll be keeping an eye out for any updates.


Top
 Profile  
 
PostPosted: Wed May 02, 2012 9:31 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Sep 19, 2005 2:34 pm
Posts: 45
Location: Suisse
Hello,
I also seek the solution but without success.
Have you finished your template mk5 ?
Where can I download it?
thank you

_________________
Sarki
Coordinator of the French Joomla Translation
http://www.joomla.fr
http://joomlacode.org/gf/project/jtranslation1_6/frs/?action=FrsReleaseBrowse&frs_package_id=5593


Top
 Profile  
 
PostPosted: Mon May 28, 2012 8:02 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Mon May 28, 2012 7:50 am
Posts: 1
hi, this works at least in 2.5:

/* /views/componentName/css/style.css.php */
<?php header("Content-type: text/css");>
.someClass { background: #<?php echo $_GET[$bg]; ?>}

/* /views/componentName/veiw.html.php */
[...]
$document->addStyleSheet($pathToComponent."css/style.css.php?bg=AAAAAA"); parent::display($tpl);
[...]


Good luck


Top
 Profile  
 
PostPosted: Tue Jul 17, 2012 4:52 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Mon Sep 14, 2009 3:13 pm
Posts: 4
Thanks for sharing your code. Passing variables over the global GET array isn't what we're after though (at least not me). What I'd really like to have is the possibility to access the Joomla template object, i.e. the object which can be referencesd by "$this" in the template. I don't know if it's called the template object but I think you know what i mean... That would be really dope. Maybe I'll be able to find out how to do it myself, but if anybody else knows how this is done, it would be great if you shared some insight!


Top
 Profile  
 
PostPosted: Thu Nov 08, 2012 9:51 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Thu Nov 01, 2012 3:50 pm
Posts: 3
The solution I used for this is the following:
First - make a sample file where the main piece of css code to be stored. Set replacable variables instead of css values in the file like this:
Code:
div{
background-color:#ReplaceMeWithColor;
float:ReplaceWithFloat;
width:ReplaceWithWidthpx;
}


Next we have to make a css.ini file with settings which will be checked for determining the case changes are made or not:
Code:
str_000,left,90

str_ is just a reminder that it's string and it isn't really needed. The other values are default values set in templateDetails.xml.
Now we need a replacement script file cssupdate.php, which in this case will look like this:
Code:
defined(_JEXEC) or die();

$getParamsForCheck = "str_".$this->params->get("ReplaceMeWithColor").",".$this->params->get("ReplaceWithFloat")
.",".$this->params->get("ReplaceWithWidth"); // getting the parameters

$getCssIni = file_get_contents("templates/".$this->template."/css/css.ini"); // getting last css settings saved

if(substr_count($getCssIni,$geParamsForCheck)==0){
//check the weather changes are made or not

$includeSampleCss = file_get_contents("templates/".$this->template."/css/sample.css");
//get sample.css contents

$stringToSave = str_replace(array("ReplaceMeWithColor","ReplaceWithFloat","ReplaceWithWidth"),
array($this->params->get("ReplaceMeWithColor"),$this->params->get("ReplaceWithFloat"),
$this->params->get("ReplaceWithWidth")),$includeSampleCss); // replace the variables

// save the css style file style.css
$openFile = fopen("templates/".$this->template."/css/style.css","w");
fwrite($openFile,$stringToSave);
fclose($openFile);

//rewrite the ini file with new settings
$openFile = fopen("templates/".$this->template."/css/css.ini","w");
fwrite($openFile,$getParamsForCheck);
fclose($openFile);

}




The last thing to do is adding the following line in the head section of template's main file:
Code:
include_once("templates/".$this->template."/css/cssupdate.php");
$document =& JFactory::getDocument();
$document->addStyleSheet("template/".$this->template."/css/style.css");



Top
 Profile  
 
PostPosted: Mon Nov 19, 2012 6:12 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Oct 23, 2007 10:58 pm
Posts: 25
hello ldn24
Do you by any chance have the actual sample files, would help a great deal to get my head around the problem.

regards

w9914420


Top
 Profile  
 
PostPosted: Wed Nov 21, 2012 11:01 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Thu Nov 01, 2012 3:50 pm
Posts: 3
I rewrote the code in functions. I'm sorry for I am a bit late in uploading. I've done the functions right after I posted the post above but it was late at night and didn't post it.

First we need the functions for updating the css values and the ini files.
There are 3 functions - with the first (CheckParams) we check the parameters set in joomla and compare them with these in the ini file.
The second function (UpdateCSS) updates the css file according to the sample file. If some changes have to be made in future with the dynamic css, this file has to be edited instead of style.css file (or whatever you have named it). If you don't the changes won't exist after the next settings change in admin panel as the style.css is being wholly rewritten.
The third function (UpdateINI) updates the ini file with the value returned by UpdateCSS.
Now - the code :
Code:
<?php
defined('_JEXEC') or die('Restricted access');
##############
if(!function_exists("CheckParams")):
function CheckParams($params=array(),$iniFile="css.ini",$prefix = "str_"){

if(!is_array($params)):echo "parameter 1 must be array!"; return false; endif;
if(!file_exists($iniFile)): echo "file in parameter 2 doesn't exist!"; return false; endif;

$check = $prefix.implode(",",$params);
$tocheck = file_get_contents($iniFile);

if(substr_count($tocheck,$check)!=0):return 1; else: return false; endif;

}
endif;

##############
if(!function_exists("UpdateCSS")):
function UpdateCSS($replacement,$replaceWith,$sampleFile="sample.css",$cssFileName="style.css"){

if(!file_exists($sampleFile)): echo "file in parameter 3 doesn't exist!"; return false; endif;


$tochock = file_get_contents($sampleFile);
$toprint_t = str_replace($replacement,$replaceWith,$tochock);

$fope = fopen($cssFileName,"w");
fwrite($fope,$toprint_t);
fclose($fope);
return implode(",",$replaceWith);
}
endif;

###############
if(!function_exists("UpdateINI")):
function UpdateINI($replaceWith,$iniFile="css.ini",$prefix="img"){
$checkstr = $prefix.$replaceWith;
if(!file_exists($iniFile)): echo "file in parameter 2 doesn't exist!"; return false; endif;



$fope = fopen($iniFile,"w");
fwrite($fope,$checkstr);
fclose($fope);
}
endif;
###############




?>


The second file is dynamiccss.php it is the file, which will be included to template's main section instead of cssupdate.php in the post above:
Code:
<?php
defined('_JEXEC') or die('Restricted access');

include_once("templates/".$this->template."/css/cssfunctions.php"); //including functions file

$updateCssParams = array($this->params->get("FieldOne"),$this->params->get("FieldTwo"),$this->params->get("FieldThree")); //getting params (must be array)

$updateCSS = CheckParams($updateCssParams,"templates/".$this->template."/css/css.ini","str"); //checking params in the ini file
##attribute 1 - params from the fields
##attribute 2 - the path to the ini file
##attribute 3 - prefix

 if(!$updateCSS){ //checking are updates neccessary or not
 echo "Currently updating CSS... \n\r";
 
$updatedCssParams = array("ReplaceMeWithColor","ReplaceMeWithWidth","ReplaceMeWithFloat"); //define replacement variables (must be array)

$asc = UpdateCSS($updatedCssParams,$updateCssParams,"templates/".$this->template."/css/sample.css","templates/".$this->template."/css/style.css");//updating the output css file
##attribute 1 - the variable strings, which have to be replaced
##attribute 2 - Replacement params
##attribute 3 - path to the sample css file
##attribute 4 - path to the output css file

UpdateINI($asc,"templates/".$this->template."/css/css.ini","str"); //Updating the ini file with new values
##attribute 1 - formated string returned by the update function
##attribute 2 - path to the ini file
##attribute 3 - prefix

echo "CSS updated! \n\r";
}
?>


The last file needed is the sample file, which doesn't differ the one above too much.
Code:
div{
background-color:#ReplaceMeWithColor;
float:ReplaceMeWithFloat;
width:ReplaceMeWithWidthpx;
}


There are another 2 files - the ini file and the outputed css file, but I won't add them as code because they are automatically created after the first execution of the code. However, they are included in the zip file below.

P.S. : Excuse my poor english, I know how annoying it is when a low - skilled newbie in coding or in english tries to do some lessons :). However I hope the code I wrote will be somehow helpful for your needs.


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
PostPosted: Wed Nov 21, 2012 10:42 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Oct 23, 2007 10:58 pm
Posts: 25
Hello IDN24

I am extremely Grateful for this, I had been using the GET method which has your already know is a big no-no. I will have a play and get mind head in your code.

Thanks again.

w9914420


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ] 



Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group