Page Class Suffix in template code

Everything to do with Joomla! 1.5 templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
User avatar
MuffinDCC
Joomla! Explorer
Joomla! Explorer
Posts: 347
Joined: Wed Nov 22, 2006 9:07 am
Location: UK
Contact:

Page Class Suffix in template code

Post by MuffinDCC » Sun Jul 13, 2008 3:06 pm

I was wondering if anyone knows how to insert the page class suffix call in the templates themselves. The command for the page class suffix in the content doesn't work here as I assume another command needs to be taken place.

I tried to create my own function to call it but it resulted in a conflict with Joomlas DB code :)

So, do you know how to call the page class suffix into the template code? :)

User avatar
jlabs
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 220
Joined: Thu Aug 18, 2005 1:54 pm
Location: FL USA
Contact:

Re: Page Class Suffix in template code

Post by jlabs » Mon Jul 14, 2008 3:51 pm

Hi
Take a look at this article.
http://www.m65.net/article-chapter-page ... 5.html#1_1

I don't think you need to hardcode the CSS to the template itself.
But just bad suffixes to the existing classes have different views on pages.

Hope this helps
Joomla Template Kit
http://dumbitdown.com

User avatar
MuffinDCC
Joomla! Explorer
Joomla! Explorer
Posts: 347
Joined: Wed Nov 22, 2006 9:07 am
Location: UK
Contact:

Re: Page Class Suffix in template code

Post by MuffinDCC » Mon Jul 14, 2008 5:50 pm

Hey,

Thanks for the reply but that is not what I was referring to. I know how to use and style a page class suffix, I even wrote a tutorial on it ( http://tutorials.rockettheme.com/joomla ... uffix.html )

The way the page class suffix works is by adding the user determined text to the .contentpane part of the HTML structure. This is all regulated by Joomla. I was wanting to have the PHP code that I can manually inject it into the template. Its quite a handy idea as I would apply it to the <BODY> tag of the template, that means the page class suffix would help you control EVERYTHING on the page.

Currently, you can only style the tables that Joomla injects as part of the content items, if the suffix was applied to the body tag, it would allow you to control every inch of the template.

User avatar
jlabs
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 220
Joined: Thu Aug 18, 2005 1:54 pm
Location: FL USA
Contact:

Re: Page Class Suffix in template code

Post by jlabs » Mon Jul 14, 2008 6:09 pm

This would be tricky because Joomla using a param

Code: Select all

MasterClassName<?php echo $this->item->params->get( 'pageclass_sfx' ); ?>
for each part of the article layouts.

1. You would have use a template override.
or
2. Come up with your own php include file that's at the last line of the
head tag to override the default class's. Base on a cookie etc.
like what yootheme.com does is not that hard to do.
or
3. Content Plug-in
Joomla Template Kit
http://dumbitdown.com

User avatar
MuffinDCC
Joomla! Explorer
Joomla! Explorer
Posts: 347
Joined: Wed Nov 22, 2006 9:07 am
Location: UK
Contact:

Re: Page Class Suffix in template code

Post by MuffinDCC » Mon Jul 14, 2008 9:14 pm

1. I wouldn't see how a template override would really help unless you were referring to overriding the Article layout and then inject some code so the page class suffix would be injected into the <head>?

2. The cookie based approach isn't difficult but is the opposite of where I wanted to be ending up. This would mean the controls would be template side instead of joomla side and I'd prefer it to be joomla side.

3. I am not aware of a plugin specifically for this purpose.

Note: this information isn't necessarily for me as I do not personally need this approach but is for other people that I help in Joomla. Having a system where any template can easily pick up the page class suffix on menu items would benefit quite a lot of people.

For myself, I'd just do some IF statements in the PHP and make it all external but workarounds are not my aim.

Thanks for your replies though :)

User avatar
jlabs
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 220
Joined: Thu Aug 18, 2005 1:54 pm
Location: FL USA
Contact:

Re: Page Class Suffix in template code

Post by jlabs » Mon Jul 14, 2008 10:05 pm

This is kind of a crazy question/requests or whatever.

The Hook via the GUI is a set by the menu link parameters in accordance with the components XML metadata.
Image

Which obviously needs an item ID to be able to render any type of Pagesuffix to an individual page
or really the component for what it looks like in the code.

this holds the clues

Code: Select all

administrator\components\com_menus\models\item.php
the trick is that every component has its meta data and parameter variables through the XML file.
So in order to pull this trick off you have to copy some of the code. The menu system understands it
even through third parties Extensions.

You'll have to force-feed the parameter value inside the database
or override as are stored inside of the #_menu Params Column.

Grabs and renders the template

Code: Select all

\libraries\joomla\document\html\html.php
look for this function render()
line 218

But you need I say more than this.
Somehow you have to go into the $mainframe etc.

I'm not a Joomla core developer.
Maybe one of them can best answer your question.

This seems a little over the top to me not to startup type of argument.
You need to add the links to the menu anyway.
You need to design the stylesheets with the page suffix anyway.

So why would you go to the trouble adding such a difficult add-on just to do something they could do in a few clicks.
But you can have to do with or without any type of extension like this?

Best of luck
Joomla Template Kit
http://dumbitdown.com

User avatar
MuffinDCC
Joomla! Explorer
Joomla! Explorer
Posts: 347
Joined: Wed Nov 22, 2006 9:07 am
Location: UK
Contact:

Re: Page Class Suffix in template code

Post by MuffinDCC » Tue Jul 15, 2008 9:12 am

I had a feeling it would require some more extensive code additions, I will look into it a bit more and see if a I can write some PHP code to call it.

However, I will try to explain the purpose behind my request as to further your understanding into my head :) This is actually more beneficial than you might think. The whole adding extra IDs to the <BODY> tag is nothing new for template developers, as you stated the YOOtheme cookie thing. This allows you to make distinctions between different pages between Joomla so you can style them differently. A common one is the font size and style changer approach. For example, just take a look at the new RT template ( http://demo.rockettheme.com/jul08/ ) - notice that the menus all have different colours which are generated from an array that is called upon in the <BODY> tag. Therefore, you can have each menu page load a whole different style variant.

That is the approach that I want to discover. Quite a lot of people use the page class suffix but then discover how limited it is. It only applies to the Component area which is just one line in the template's index.php ( <jdoc:include type="component" /> ) therefore, its control is highly restrictive in what you might think. For example, from a query I was dealing with a few days ago related to ( http://demo.rockettheme.com/jun08 ) - he wanted to use a page class suffix so that the entire white area could be made black for that page, however, the white background is generated for <div id="mainbody"> which is around 10 hierarchical layers above what the page class suffix injects itself to. Obviously, the page class suffix wouldn't really work.

Therefore, another approach was recommend using some PHP IF statements such as


<?php if (JRequest::getVar('view') = 'wrapper') : ?>
#mainbody { background-color: #000 !important; }
<?php endif; ?>

And that would be placed in the <STYLE> tag area of the template. This is a workaround. However, if the page class suffix was injected into the body tag, this wouldn't have been necessary. You'll find that adding PHP code is more daunting to people than adding to CSS. It would just be an added benefit and making individual page customisations even easier. Obviously, there are a plethora of other approaches to take but this would add another option to the basket :)

Anyway, I'll see what I can do as I anticipate only you will be replying to this thread :)

barreguillen
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Wed Jun 18, 2008 1:12 am

Re: Page Class Suffix in template code

Post by barreguillen » Wed Jul 16, 2008 2:43 am

Hi I found this code on another site which worked for me...

This goes directly above the <body> tag:

Code: Select all

<?php
$menus   = &JSite::getMenu();
$menu   = $menus->getActive();

if (is_object( $menu )) $params = new JParameter( $menu->params );
$pageclass = $params->get( 'pageclass_sfx' );
?>
This goes within the <body class="">:

Code: Select all

<?php echo $pageclass;?>
The problem I'm having is that I get the error "Fatal error: Call to a member function get() on a non-object on line 52" when I try to use certain feature like Search for example. Any ideas or help would be appreciated.

Thanks,

Barré

User avatar
MuffinDCC
Joomla! Explorer
Joomla! Explorer
Posts: 347
Joined: Wed Nov 22, 2006 9:07 am
Location: UK
Contact:

Re: Page Class Suffix in template code

Post by MuffinDCC » Wed Jul 16, 2008 5:46 am

You my friend are awesome! :D

That's exactly what I needed. The error you are getting is probably related to an item which isn't linked within the menu system. I'll look into that later on to avoid that fatal error.
barreguillen wrote:Hi I found this code on another site which worked for me...

This goes directly above the <body> tag:

Code: Select all

<?php
$menus   = &JSite::getMenu();
$menu   = $menus->getActive();

if (is_object( $menu )) $params = new JParameter( $menu->params );
$pageclass = $params->get( 'pageclass_sfx' );
?>
This goes within the <body class="">:

Code: Select all

<?php echo $pageclass;?>
The problem I'm having is that I get the error "Fatal error: Call to a member function get() on a non-object on line 52" when I try to use certain feature like Search for example. Any ideas or help would be appreciated.

Thanks,

Barré

barreguillen
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Wed Jun 18, 2008 1:12 am

Re: Page Class Suffix in template code

Post by barreguillen » Wed Jul 16, 2008 4:50 pm

Great! I'm glad.

I forgot to clarify that the problem, line 52, is this line:

Code: Select all

$pageclass = $params->get( 'pageclass_sfx' );
When I comment out the line, the problem goes away, but I also lose the pageclass feature in the <body> tag. Any help you could offer would be great. Thanks.

Barré

User avatar
jlabs
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 220
Joined: Thu Aug 18, 2005 1:54 pm
Location: FL USA
Contact:

Re: Page Class Suffix in template code

Post by jlabs » Wed Jul 16, 2008 8:38 pm

I'm work on a free menu module and I did run into something for you.
add this to your Template and you will see the array Dump.

Code: Select all

  <?php 
echo '<pre>';
echo var_export(JSite::getMenu());
echo '</pre>';
?>
You need to be specific to which menu are working on when adding this code.
What you're calling is the entire array which is nested
Joomla Template Kit
http://dumbitdown.com

barreguillen
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Wed Jun 18, 2008 1:12 am

Re: Page Class Suffix in template code

Post by barreguillen » Wed Jul 16, 2008 9:19 pm

Thanks. This makes sense. But I'm not sure this will address the "Fatal error: Call to a member function get() on a non-object on line 52" issue that I'm having. Do you think they're related?

User avatar
MuffinDCC
Joomla! Explorer
Joomla! Explorer
Posts: 347
Joined: Wed Nov 22, 2006 9:07 am
Location: UK
Contact:

Re: Page Class Suffix in template code

Post by MuffinDCC » Thu Jul 17, 2008 3:00 pm

This code works for me and doesn't display any errors.

Code: Select all

<?php
$menus 	 = &JSite::getMenu();
$menu   	 = $menus->getActive();
$pageclass = "";
	
if (is_object( $menu )) : 
$params = new JParameter( $menu->params );
$pageclass = $params->get( 'pageclass_sfx' );
endif; 
?>
</head>
<body class="<?php echo $pageclass; ?>">
*This is my 3rd edit of this post with all the code lol :D *
Last edited by MuffinDCC on Thu Jul 17, 2008 7:14 pm, edited 1 time in total.

barreguillen
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Wed Jun 18, 2008 1:12 am

Re: Page Class Suffix in template code

Post by barreguillen » Thu Jul 17, 2008 5:27 pm

Great! This works. Thanks so much!

User avatar
jlabs
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 220
Joined: Thu Aug 18, 2005 1:54 pm
Location: FL USA
Contact:

Re: Page Class Suffix in template code

Post by jlabs » Thu Jul 17, 2008 7:02 pm

I have not had change to test it. but I'm glad you guys got it working.
Cheers
B
Joomla Template Kit
http://dumbitdown.com

User avatar
MuffinDCC
Joomla! Explorer
Joomla! Explorer
Posts: 347
Joined: Wed Nov 22, 2006 9:07 am
Location: UK
Contact:

Re: Page Class Suffix in template code

Post by MuffinDCC » Thu Jul 17, 2008 7:29 pm

I modified the code so it was a bit leaner, it was a bit ... long winded as I was testing it out. So, for anyone wanted to implement it, just follows these steps:-

1. Open your template's index.php file (located in /templates/*template-name*/)

2. Find the </head> tag in the index.php, should be near the top area of the template

3. Above this, insert

Code: Select all

	<?php
	$menus		= &JSite::getMenu();
	$menu		= $menus->getActive();
	$pageclass	= "";
 	
	if (is_object( $menu )) : 
 	$params = new JParameter( $menu->params );
	$pageclass = $params->get( 'pageclass_sfx' );
 	endif; ?>
4. Find the <body> tag in the index.php, should be after the </head> tag infact. Depending on your template, it may have other variables in it such as my testing template (Firenzie) which has <body class="<?php echo $fontstyle; ?>">

5. Insert <?php echo $pageclass; ?> into the body tag. There are a few ways to do this depending on how the template is setup already. Some examples below:-

a. If the <body> tag is empty, add a class with the PHP code in step5 so it mimics the following:

Code: Select all

<body class="<?php echo $pageclass; ?>">
b. If the <body> tag is empty, add an ID with the PHP code in step5 so it mimics the following:

Code: Select all

<body id="<?php echo $pageclass; ?>">
c. If the <body> tag already has a class, add a space after the class name and insert the the PHP code in step5 so it mimics the following:

Code: Select all

<body class="<?php echo $fontstyle; ?> <?php echo $pageclass; ?>">
d. If the <body> tag already has a class, and you want to add this as an ID, create the ID in the <body> tag and insert the the PHP code in step5 so it mimics the following:

Code: Select all

<body id="<?php echo $pageclass; ?>" class="<?php echo $fontstyle; ?>">

bigblue
Joomla! Apprentice
Joomla! Apprentice
Posts: 45
Joined: Mon Jul 30, 2007 1:03 pm

Re: Page Class Suffix in template code

Post by bigblue » Sat Aug 02, 2008 2:53 pm

This is excellent.. although I've been trying to implement this code, but can't seem to get it to work..

I've inserted into the body tag as shown below.. although I'm not sure if it should be in the id or the class.. could you advise if this is correct?

Code: Select all

<body id="<?php echo $pageclass; ?> ff-<?php echo $fontfamily; ?>" class="<?php echo $tstyle; ?> <?php echo $fontstyle; ?>">
I'm using RocketTheme's Hyperion 1.5 template, but want to have a different body background image (or colour) for each page that I link to from the mainmenu, and have been going round in circles trying to do it !

Once this code has been inserted, how do I then set up the css and the page class suffix to work.. eg. if I want a red body background on a particular page?

Cheers

User avatar
MuffinDCC
Joomla! Explorer
Joomla! Explorer
Posts: 347
Joined: Wed Nov 22, 2006 9:07 am
Location: UK
Contact:

Re: Page Class Suffix in template code

Post by MuffinDCC » Sat Aug 02, 2008 3:09 pm

I would use

Code: Select all

<body id="ff-<?php echo $fontfamily; ?>" class="<?php echo $tstyle; ?> <?php echo $fontstyle; ?> <?php echo $pageclass; ?>">
Only have one ID, but multiple classes.

bigblue
Joomla! Apprentice
Joomla! Apprentice
Posts: 45
Joined: Mon Jul 30, 2007 1:03 pm

Re: Page Class Suffix in template code

Post by bigblue » Sat Aug 02, 2008 3:33 pm

Thx Muffin.. just tried that and it's still not having it though!

As a test, I've used '_red' as the page class suffix for a menu - and in my stylesheet I have this:

Code: Select all

body {color: #ccc; background: #000;}
#page-bg {background: url(../images/style10/page-bg.jpg) 50% -85px repeat-x;}
..I commented out the #page-bg to remove the image for now and tried adding #page-bg_red {background: #cc0000;} to the sheet, but it's not working.. am I doing this right? Also, how would I implement this with just the body {background: #000;} ?

Thx

User avatar
MuffinDCC
Joomla! Explorer
Joomla! Explorer
Posts: 347
Joined: Wed Nov 22, 2006 9:07 am
Location: UK
Contact:

Re: Page Class Suffix in template code

Post by MuffinDCC » Sat Aug 02, 2008 3:57 pm

That is not how it will work. The class is being applied to the body tag, so your code would be

body._red #page-bg { background-color: #cc0; }

This is because the class of _red is applied to the <BODY> tag which results in body._red ... and #page-bg is a sub level div below the body tag so is placed after body._red

bigblue
Joomla! Apprentice
Joomla! Apprentice
Posts: 45
Joined: Mon Jul 30, 2007 1:03 pm

Re: Page Class Suffix in template code

Post by bigblue » Sat Aug 02, 2008 4:53 pm

Wonderful stuff.. you're a star! This works just as I wanted. I understand what you're saying now re. <BODY> tag and I've learned something new. It wouldn't work with 'background-color' though which is strange, so I changed it to just 'background' and that fixed it.

Thx Muffin.. I really appreciate your time helping me with this.. not everyone understands the finer points of Joomla and guides/tutorials from people such as yourself are really helpful in getting to grips with it all and understanding it more.

Thx again!

webRtist
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Jun 13, 2008 5:04 am

Re: Page Class Suffix in template code

Post by webRtist » Tue Aug 12, 2008 8:51 am

Thank you! Thank you!
I've been looking for this type of functionality for days. It can be used for SO MANY things. I will use it for different header images on pages for one site I'm working on right now and for different decorative background images on another site.

Now I just have to figure out how to apply different css styles to 3 different articles on the same page - but that's another post. :-)

Thank You!

Jaril
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Mon Aug 27, 2007 6:42 pm

Re: Page Class Suffix in template code

Post by Jaril » Tue Aug 19, 2008 2:13 pm

his code works for me and doesn't display any errors.

Code: Select all

    <?php
    $menus     = &JSite::getMenu();
    $menu       = $menus->getActive();
    $pageclass = "";
       
    if (is_object( $menu )) :
    $params = new JParameter( $menu->params );
    $pageclass = $params->get( 'pageclass_sfx' );
    endif;
    ?>
    </head>
    <body class="<?php echo $pageclass; ?>">
this works great

User avatar
mark_up
Joomla! Guru
Joomla! Guru
Posts: 849
Joined: Sun Oct 29, 2006 10:51 am
Location: Fiji
Contact:

Re: Page Class Suffix in template code

Post by mark_up » Sun Sep 21, 2008 3:58 am

Glad you persevered with this MuffinDCC, many thanks ;)

Now, to lobby to have J1.6 scrap page class suffixes and replace them with page classes.. and output to the <body> tag!

:)
http://twitter.com/mark_up.
Opinions expressed are mine alone and don't necessarily represent the views of any organisation I am associated with.

User avatar
MuffinDCC
Joomla! Explorer
Joomla! Explorer
Posts: 347
Joined: Wed Nov 22, 2006 9:07 am
Location: UK
Contact:

Re: Page Class Suffix in template code

Post by MuffinDCC » Sun Sep 21, 2008 9:11 am

GollumX wrote:Glad you persevered with this MuffinDCC, many thanks ;)

Now, to lobby to have J1.6 scrap page class suffixes and replace them with page classes.. and output to the <body> tag!

:)
Lol, I believe in persistent nagging :)

ralphonz
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Mon Oct 20, 2008 3:58 pm

Re: Page Class Suffix in template code

Post by ralphonz » Mon Oct 20, 2008 4:14 pm

Hi guys,

I've been looking for a while and this seems pretty close to what i'm looking for. I'm using the RT template 'replicant' and want different content pages to display a different template 'style' preset of which there are 50.

The styles for these are held in the rt_styles.php file, is there a way to call these styles using the page class suffix??

Great work and thanks in advance!

User avatar
mark_up
Joomla! Guru
Joomla! Guru
Posts: 849
Joined: Sun Oct 29, 2006 10:51 am
Location: Fiji
Contact:

Re: Page Class Suffix in template code

Post by mark_up » Mon Oct 20, 2008 9:19 pm

Ralphonz, in your case, if you're using J1.0, you might attempt it first with:
http://extensions.joomla.org/component/ ... Itemid,35/
http://twitter.com/mark_up.
Opinions expressed are mine alone and don't necessarily represent the views of any organisation I am associated with.

ralphonz
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Mon Oct 20, 2008 3:58 pm

Re: Page Class Suffix in template code

Post by ralphonz » Tue Oct 21, 2008 11:39 am

Looks perfect!

Thanks! Can't believe i missed it.

ralphonz
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Mon Oct 20, 2008 3:58 pm

Re: Page Class Suffix in template code

Post by ralphonz » Tue Oct 21, 2008 6:53 pm

Hi,

I've tried style ninja but this doesn't work for me as my templates styles are not contained in individual css files but in one php file. That is why i thought the page suffix might solve my problem if it were able to call different styles from this php file.

So far i haven't found anything which might enable me to hack the style ninja module so that it can identify with the styles in the php file rather than be directed to a css file,

another possibility could be to hack my template so that styles are included in separate css files rather than in one php file but I think I might be way out of my depth with this one as I'm not a confident php coder!

If anyone has any suggestions then it much appreciated!

Thanks

User avatar
mark_up
Joomla! Guru
Joomla! Guru
Posts: 849
Joined: Sun Oct 29, 2006 10:51 am
Location: Fiji
Contact:

Re: Page Class Suffix in template code

Post by mark_up » Tue Oct 21, 2008 8:28 pm

Could you link me to your site please.
http://twitter.com/mark_up.
Opinions expressed are mine alone and don't necessarily represent the views of any organisation I am associated with.


Locked

Return to “Templates for Joomla! 1.5”