Customizing SMF > Now Available

How to create custom 'action'

(1/22) > >>

Owdy:
Notice:
This tip has been in some way ported over to be a modification package located on the SMF modsite. Please note, the mod package may not do the exact same function and may not even use any of the code originally written for the tip, but should still hold the same basic functionality of the tip posted here. With the mod package for this tip, you can now let the SMF package manager make the code changes for you without you having to look at the code and edit it manually.

For documentation on using the SMF package manager, view this document.

To download the modification package, please click here.If you need your custom action, here's howto. Lets say you want own dowload area.

index.php find:


--- Code: ---'activate' => array('Register.php', 'Activate'),
--- End code ---

ad after:


--- Code: ---'downloads' => array('Downloads.php', 'Downloads'),
--- End code ---

Then create 'Downloads.php' like this:

--- Code: ---<?php
if (!defined('SMF'))
die('Hacking attempt...');

function Downloads() {
global $context;
$context['page_title'] = 'My Actions title!';
// This is gonna be needed...
loadTemplate('Downloads');
}
?>
--- End code ---
Put that Downloads.php to /Sources/

Then, create to Themes/default/Downloads.template.php, something like this:


--- Code: ---<?php

function template_main()
{
global $context, $settings, $options, $txt, $scripturl;

echo '


<table width="100%" border="0" cellspacing="0" cellpadding="3" >
<tr>
<td>', theme_linktree(), '</td>
</tr>
</table>

<table width="100%" border="0" cellspacing="0" cellpadding="4" align="center" class="tborder">
<tr class="titlebg">
<td align="center" >Download area</td>
</tr><tr>
<td class="windowbg">';
 
echo '<table border="0" cellpadding="0" cellspacing="3" width="100%">
         <tr>
           <td width="100%" valign="top">
  MY cool downloads!!!!
</td></tr></table>';
echo '
</td>
</tr>
</table><br /><br />
';
}

?>
--- End code ---

Then just do this http://www.example.com/smf/index.php?action=downloads
You can change that 'Downloads' and modify that theme file to fit your needs.

DEMO: http://www.halko.net/smf/index.php?action=test

Enjoy :)

[Unknown]:
Also read this, which is related but tied to themes:

http://www.simplemachines.org/community/index.php?action=dlattach;topic=7703.0;id=3102

-[Unknown]

CapriSkye:
is there an example of this?

Kirby:
For the themes one, there is in Unknowns guide. I've begun integrating the vCard option that was in IPB to my IPB theme using action wrapping :P

Jerry:

--- Quote from: Owdy on January 09, 2005, 05:01:30 PM ---Then create 'Downloads.php' like this:

--- Code: ---<?php
if (!defined(&#39;SMF&#39;))
die(&#39;Hacking attempt...&#39;);

function Downloads() {
// This is gonna be needed...
loadTemplate(&#39;Downloads&#39;);
}
?>
--- End code ---
Put that Downloads.php to /Sources/
--- End quote ---
I don't think this will show a page title (some one stuff a sock in my mouth if  I am wrong ;)) to make the new action have a page title you would need to do this:

--- Code: ---<?php
if (!defined(&#39;SMF&#39;))
die(&#39;Hacking attempt...&#39;);

function Downloads() {
global $context;
$context[&#39;page_title&#39;] = &#39;My Actions title!&#39;;
// This is gonna be needed...
loadTemplate(&#39;Downloads&#39;);
}
?>
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version