Topic specific template

Started by pittu, April 07, 2015, 05:52:00 PM

Previous topic - Next topic

pittu

I want topics (topics alone) in some forums are displayed with different template.

Instead of duplicating Curve and editing topic display file, is there any other simple way to do it?

(BTW, which template displays topic and its replies?)

Deaks

simply no

Due to how SMF is designed this is not possible in an easy way and to do it would take ALOT of work.
~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

pittu

OK. than I will duplicate 'Curve' and copy Display.template.php and do changes.

thnx.

Suki

It is actually pretty easy to accomplish this.

At the end of function Display()  in Sources/Display.php add this:

$context['sub_template'] = 'other';

and in your Display.template file add a simple function:
function template_other()
{
   echo 'LOL';

}

That will overwrite the main()  template with your template_other()  function.  You can put whatever you want on that template.

You can put some conditionals too:

   if ($board == 1)
      $context['sub_template'] = 'other';

Thats for showing that template on the board with ID 2.

If you want to show multiple templates for multiple boards then a switch will be better:

find this:


else
loadTemplate('Display');

      replace with this:

else
{
loadTemplate('Display');

switch ($board)
{
case 1:
$context['sub_template'] = 'template for board ID 1';
break;
case 2:
$context['sub_template'] = 'template for board ID 2';
break;
case 3:
$context['sub_template'] = 'template for board ID 3';
break;
default: $context['sub_template'] = 'main';
}
}
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

pittu

Only one extra template for 4 forums. All others display using default 'Curve'.

So if this works, where can I keep this?

  if ($board == 1,3,5)
      $context['sub_template'] = 'other';

Suki

On your Sources/Display.php file find this:



else
loadTemplate('Display');



      And replace it with this:

else
{
loadTemplate('Display');

if(in_array($board, array(1,3,5)))
$context['sub_template'] = 'other';
}


Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

pittu

After I replacing this code, I need to create a template for boards 1,3 and 5?

What should I name the template?

thnx.

Suki

This part indicates what your template should be named:

$context['sub_template'] = 'other';


Your template should be named template_other:

function template_other()
{
   echo 'LOL';

}

And you only need one template since thats what you said you want and thats why I asked if you are ever going to use more templates.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

pittu

OK. These are the steps:

1. At the end of function Display()  in Sources/Display.php add this:

$context['sub_template'] = 'other';


2.In Display.template.php file add a simple function at the end:

function template_other()
{
   echo 'LOL';

}



3. On your Sources/Display.php file find this:


else
loadTemplate('Display');

      
And replace it with this:

else
{
loadTemplate('Display');

if(in_array($board, array(1,3,5)))
$context['sub_template'] = 'other';



4. Create a template by name 'template.other.php' in /Themes/Default/ folder. (I can duplicate Display.template.php and rename it template.other.php and make changes to it?


Above steps are correct?

thnx.
   

Suki

Disregard step one you do not need that if you are doing step 3.

Step 4 is incorrect and unnecessary, yo do not need to create a file, you already created the template function in step 2.

If you want to duplicate some functionalities from the default display template then put then inside your function template_other()
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Advertisement: