Using multiple Templates

In this board you can talk about general questions about phpMyFAQ

Moderator: Thorsten

Post Reply
Rob
Posts: 5
Joined: Tue Jun 20, 2006 7:37 pm

Using multiple Templates

Post by Rob »

Is there are way to specify which template is used for a page?

I would like to use one template for the main page, and different templates for each category.

Thanks,
Rob
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi Rob,
currently (PMF 1.6.x) this is not possible without some hacking the PMF code, that is to say, the code into some files other than those included into the template folder.
Basically, it depends on your goals and skills, but you could make some hacks by your own in a simple manner. See e.g. this long post and its result.
Just for helping you with a possible direction, take a look at the [PATH_TO_PMFINSTALL]/index.php file which is the file involved in loading each section/template in the anonymous user context: you'll see that:

Code: Select all

$inc_tpl
$inc_php
contain respectively the template file and the code file involved in a particular action.
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
Rob
Posts: 5
Joined: Tue Jun 20, 2006 7:37 pm

Post by Rob »

matteo,

Thanks for the tips. I will probably have to come up with a hack of some sort. The reson for my question is that I wanted to remove the right column from all the artikel pages (So there is more room for content).

The current plan is to make a second style sheet that overwrites the main styles if the action="artikel".

I will post back to let the board know if it is a success (or not).

Thanks!
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi Rob,
Rob wrote:The reson for my question is that I wanted to remove the right column from all the artikel pages (So there is more room for content).
Well, try this code below, a small PHP hack plus using CSS display style property*:
  1. open the template/artikel.tpl and add this line at the beginning:

    Code: Select all

    <script type="text/javascript">{cutDownRightColumn}</script>
    
  2. open the artikel.php file for managing the new key, cutDownRightColumn, in the template

    Code: Select all

    ...
                    "writeComments" => generateComments($id),
                    // This below is the new line
                    "cutDownRightColumn" => 'window.document.getElementById("sidebar-right").style.display = "none";'
                    ));
    ...
  3. Change the centercolumn CSS class removing the margin-right declaration.
That's all :wink: ! This is a rough sample to implement your request.
I suggest you also to find a solution as the best trade-off between your custom requirement and the minimun number of changes needed to reach it. This will help you in mantanining your faq server from an upgrading standpoint.

*I'd prefer a pure PHP driven solution but see my note about PMF upgrading.
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
Rob
Posts: 5
Joined: Tue Jun 20, 2006 7:37 pm

Post by Rob »

Yep, that is what I finally figured out as well.

Added to artikel.php:

Code: Select all

  $extrastyles = '<link href="template/style2.css" type="text/css" rel="stylesheet" media="screen" />';

$tpl->processTemplate ("writeContent", array(
				"extrastyles" => $extrastyles,...

And added to artikel.tpl

Code: Select all

{extrastyles}
Where the css is:

Code: Select all

.rightcolumn {
   visible: hidden;
   display: none;
}
.centercolumn {
   margin: 0px;
   padding: 0px;
   margin-left: 210px;
}
Thanks for help.

This is such a great Program!
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi Rob,
glad to see that you've reached the goal by your own :wink:
Welcome to the PMF Community :) !

Ciao,
Matteo
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
Post Reply