PDA

View Full Version : Dynamic Templates


72dpi
09-06-2007, 03:37 AM
Hiya,

XhUnTeR helped me "hide/show" a div if no plugins were available, by doing:

<?
if($pluginpath[0] != 'plugins/p1_empty/empty.php' OR $pluginpath[1] != 'plugins/p1_empty/empty.php' OR $pluginpath[2] != 'plugins/p1_empty/empty.php') {
echo '<img src="skins/72dpi_grunge/images/cpanel_button.png" alt="Cpanel" width="81" height="18" border="0" />';}
?>

What I want to do is, use this as the basis of a new skin, where there is ONE layout, that works by using dynamic Divs, where content is only written out if a plugin has been associated to it.

The Theory:

0,1,2 (plugins) are in my Header
3,4,5,6,7,8,9,10 (plugins) are in my main Body
11,12,13,14,15 (plugins) are in my right column

In my <head> i want to declare these variables.
$headerplugins = array($pluginpath[0],$pluginpath[1],$pluginpath[2]);
if (!$headerplugins) {
$TopColumn = "hide"
}


Ok, SO my php Sucks, but MY theory is good.
I want to create a new variable, show/hide, or whatever, determined by the reults.

THis templating theory will be used in a Public release, so anyone wanting to help will help build our community !

Any thoughts?

Cheers

Ryan

TullyMan
09-06-2007, 03:41 AM
I'm not seeing where your problem is, from what i see it seems like the variable you want to use works. Are you having problems trying to check the array?

72dpi
09-06-2007, 04:15 AM
Hey Tully,
it's more along the lines of, would this work? =)

if it does, it opens up the path for Dynamic templates.

I suck @ php, so just wanted to know if this was the best way to do things.

Cheers matey

TullyMan
09-06-2007, 04:19 AM
When it comes to arrays im just learning, but my guess is to check if theres something in those plugins it'd be something like

if(in_array("p1_empty/empty.php", $headerplugins))
{
echo ''; // nothing
}
else
{
echo ''; // show cpanel
}

http://us3.php.net/in_array

It checks if the plugin path = the empty state and runs the else statement only if theres a plugin.
Im sure you'd have to mess around with the ("p1_empty/empty.php", $headerplugins) part to get it right. (or just ask xhunter which is what i would do hah)

72dpi
09-06-2007, 04:47 AM
Thats spot on the money mate =)

That was similar to my next step, cept I was saying if $Headerplugins == "plugins/p1_empty/empty.php"


<?php
$headerplugins = array($pluginpath[0],$pluginpath[1],$pluginpath[2]);

if(in_array("plugins/p1_empty/empty.php", $headerplugins))
{
echo "NO Plugins!";
}
else {
echo "There are Plugins!";
}
?>Thanks matey, This is gonna be an interesting one, as the Template will build according to whatever you want, IE 1 template to Rule them all heh heh.

I guess the other way to do it, is determine if the variable "$i" is between the ranges ogf a certain range. Will look this one up too.
So maybe like:

if (!ereg('^[0-3]') {
Or
if (range(0, 3)) {

Maybe???


Thanks for the quick php tip mate! (Thats why I stick to design =)


<= Buys Tully a Virtual Beer

TullyMan
09-06-2007, 04:58 AM
Hah glad i can actually be of assistance for once. =]

But the in_array check will not display any plugins even if one of the paths isnt the plugins/p1_empty/empty.php plugin.

So you'll want to use this instead. (notice the ! before in_array)

<?php
$headerplugins = array($pluginpath[0],$pluginpath[1],$pluginpath[2]);

if(!in_array("plugins/p1_empty/empty.php", $headerplugins))
{
echo "There are Plugins!";
}
else
{
echo "NO Plugins!";
}
?>

Cheers.

72dpi
09-06-2007, 05:03 AM
aaah, Good Point..... =)

Well, if this gets nailed, then look at templates this way:

1 Template, with 3 Columns. For each category you make, you can place them in Left Middle or Right.
The Variables are counted, and the Template designs itself according to your CSS.

This is gonna be awesome if I can figure it out, and means you can place menu on Left, Right, or have full Center content.

Smarter templates are what's needed, but I also feel there is a need for a "Template Control" plugin, but this means that All templates need to be running the same "base" principles...

<-- Edit, it Seems the "!" didn't make much difference to mine, even If I have 1 Plugin, it says No PLugins.. Very odd.

Thanks tho, Works a lot better!

<?php
$headerplugins = array($pluginpath[0],$pluginpath[1],$pluginpath[2]);

if(!in_array("plugins/p1_empty/empty.php", $headerplugins))
{
echo "There are Plugins!";
}
else
{
echo "NO Plugins!";
}


//testing the function
$test = array($pluginpath[0],$pluginpath[1],$pluginpath[2]);


echo "<pre>";
print_r($test);
echo "</pre>";

?>
<-- Am using this to test..

TullyMan
09-06-2007, 05:34 AM
Did you copy and paste what i put or did you just edit the if() part?

Well im no array expert so what i think works might not work, as we see here hah.

72dpi
09-06-2007, 05:39 AM
Mate, ou got the process working, just seems strange. perhaps its time to send R2D2 off to find XHuner1Kenobe

TullyMan
09-06-2007, 05:50 AM
Danger Will Ryanson, well im sure he'll figure out where the wires are a little loose haha. I've used this check for a file upload and it works flawlessly for me. Not too sure why it doesnt work for you. Have you tried using only p1_empty/empty.php instead of plugins/p1_empty/empty.php ?

I use the trial and error effect a lot. Timely but usually gets the effect you wish for.

XhUnTeR
09-06-2007, 07:06 AM
hey guys,
I am already using something similar, but I think it will get tricky if different designs (according to the number of chosen plugins) have very different layouts.

I started using it when I needed to change my template to support 27+ plugins in different places yet not loosing the structure when less plugins are used,

I initially used to create numbers for the non empty plugins so this way by knowing also how many they are I could manipulate the width of the site columns so it won't get messy, but using arrays is also a great idea.

for instance if the top part of the site is divided like this into 3 columns:
|20%|60%|20%|

then if lets say no plugin is selected for the first column, I would want to change the widths to :
|75%|25%|

you see why it gets tricky for such designs because you must predetermine the width(/class/style) of the columns according to all of the plugins in advance before starting to show them.

what it means is like this, lets say for 24 plugins in 3 columns right, middle and left (also don't forget about having unique variables, these are not inside a function and therefore might effect the plugins).


$right = 0;
$middle = 0;
$left = 0;
for($i = 0; $i < 8; $i++) { if($pluginpath[$i] != 'plugins/p1_empty/empty.php') { $right += 1; }}
for($i = 8; $i < 16; $i++) { if($pluginpath[$i] != 'plugins/p1_empty/empty.php') { $middle += 1; }}
for($i = 16; $i < 24; $i++) { if($pluginpath[$i] != 'plugins/p1_empty/empty.php') { $left += 1; }}


then I can set the sizes for instance like the example above:


if ($right == "0" AND $left == "0")
{$middlesize= '100%';}
elseif ($right == "0" OR $left == "0")
{$sidesize = '25%'; $middlesize= '75%';}
else
{$sidesize = '20%'; $middlesize = '60%';}


where $sidesize and $middlesize are set to create a design according the the number plugins.

and of course now you can set to show the columns or not

eg


if ($right > 0) {
show the column and the plugins [1]-[8] in the right size and etc
}



but as you mentioned it could also be a good idea to use array (might be even cleaner)

that is eg this way :

for($i = 0; $i < 3; $i++) { if($pluginpath[$i] != 'plugins/p1_empty/empty.php') { $headerplugins[]=$pluginpath[$i]; }}

if(count($headerplugins) > 0 ){
show header plugins
}



$headerplugins is only set with the nonempty plugins and with count() you even have access to the number of them.

good luck!

72dpi
09-06-2007, 08:20 AM
Spot On Mate.

That will be sweet =)

I want to make templates even better. Still want to create a global style by which we all adhere to, and in doing so, create a "templates" p[lugin to modify whatever variables you want.

Thanks!

TullyMan
09-06-2007, 08:24 AM
If we were to do the global style it would make creating and editing skins a lot easier, all the names would be exactly the same but they'd have to be very unique to be globally used.

Im trying a menu system from dynamic drive thats simple js that im not having much fun with haha.

72dpi
09-06-2007, 08:31 AM
Hey Tully, what you trying to do with your menu mate?

I have a nice one that you can control by modding CSS (Used on grunge skin)

Good Luck with it!

XhUnTeR
09-07-2007, 05:25 PM
Spot On Mate.

That will be sweet =)

I want to make templates even better. Still want to create a global style by which we all adhere to, and in doing so, create a "templates" p[lugin to modify whatever variables you want.

Thanks!

that's a good idea, but it should be considered more centrally controlled (setting the vars before loading the skin) rather than plugins, otherwise you should create eg a pluing specifically for your skin and manually load plugin settings in your skin (like is done in a real plugin) to make sure the settings are set ,

I have always thought that skin functions of SD should be improved,

firstly to have more control on the content of the skins from inside the admin panel, something like VB that templates are saved in the database and are evaluated in the actual skin files, so the templates themselves are editable inside the admin panel and that you could even have a history of changes you made.
or at least something like joomla (I guess, if I remember well), that the skin file can be opened and modified inside the admin panel (which probably requires write permissions which is not a big deal).
this way SD admin panel/plugins could actually manipulate the skins specially when it is compartmentalized (eg header, style, body, footer).

and also more advanced plugin position control, Skin Changer from condev1972 was a good step, but I was thinking about all the plugin positions being automatically saved/restored on skin switch for all the installed skins, in a manner that provides the possibility to have actual multiple skins and actual skin switchers that use the previously saved positions for those skins regardless of the current skin.
(I would have wanted to do this, it should be well thought of but it is not very complicated specially with lots capable coders here, but I am very busy to start such a project,)

72dpi
09-08-2007, 11:35 AM
Understandable X, and as always your input is invaluable, thanks!

This certainly opens up considerations for the future...

william
09-14-2007, 12:03 AM
hey guys,
I am already using something similar, but I think it will get tricky if different designs (according to the number of chosen plugins) have very different layouts.

.........

for instance if the top part of the site is divided like this into 3 columns:
|20%|60%|20%|

then if lets say no plugin is selected for the first column, I would want to change the widths to :
|75%|25%|

you see why it gets tricky for such designs because you must predetermine the width(/class/style) ..........

what it means is like this, lets say for 24 plugins in 3 columns right, middle and left (also don't forget about having unique variables, these are not inside a function and therefore might effect the plugins).


Seems very familiar to what Robert did on SDDepot with his Grip series skins... (supports 64 plugins, dynamically) can't wait to see your implementation.