V4.1.x how to use a hook?

Discussion in 'Modules / Plugins / Modifications' started by tlombard, Apr 10, 2010.

  1. tlombard Customer

    I have not used a hook yet...BUT would like to.

    in the search.tpl file there is this:

    {modulehook function="tpl_search_footer" options=""}

    What file do I find where I would utilize this function?

    -Tom
  2. Lhotch curmudgeon

    hooks tie into the module system. You can write a moduel and specify the hook taht is used for parts of you module and then anytime a hook is called, in the php or template your mod will place its code/template at that hook point.

    Read the developer documentation at the following link.
    68 Classifieds Docs - 68 Classifieds
  3. tlombard Customer

    ok:

    in the search.tpl file there is this:

    {modulehook function="tpl_search_footer" options=""}

    Lets say I want 'HELLO WORLD' to display in the footer of the search page...and I want the code or the 'Hello World' to be in a hook.

    I'm not finding an example of this OR understanding how to make this happen...if I create a module...how does it know to look to that Module...I dont get it?

    -Tom
  4. Lhotch curmudgeon

    Look at the code in the writing a module tutorial.

    Modules - 68 Classifieds

    The example shows you exactly whats needed.


    $modules->register('admin_tpl_layout_category', $this, 'admin_links');

    When you look at the above line from the example it registers a function from you module to be displayed when a certain hook is called. In the above example 'admin_link" is YOUR function that will get displayed when the hook "admin_tpl_layout_category" is encountered.
  5. tlombard Customer

    I have previously read that modules pages...it did not help... I'm not creating a new module, I'm simply trying to utilize an existing hook in the default template.

    There are hooks scattered through the default template.

    These are not third party modules... and I cannot figure out where the hooks file is for the default template, for example. Can someone please break it down to it's basics:

    How do I simply display "hello world" using the search page footer hook?
    {modulehook function="tpl_search_footer" options=""}

    Tom
  6. Lhotch curmudgeon

    you create a module. As ive already stated "hooks tie into the module system.".
  7. tlombard Customer

    Let me try a different approach.
    What am I doing wrong for 'Hello World' to not display in the footer of the search page.

    I have switched over to my Evo-Ocean template.

    #1
    I have created a folder under modules called 'templatetweaks'

    #2
    I have created a config.php file:
    PHP:
    <?php
        $data
    ['module']['name'] = "templatetweaks";
        
    $data['module']['displayname'] = "Template Tweaks";
        
    $data['module']['description'] = "Allows Us to use Template Hooks";
        
    $data['module']['version'] = "v1";
        
    $data['module']['admin_capable'] = "0";
        
    $data['module']['user_capable'] = "1";
    ?>
    #3
    I have created a hooks.php file:
    PHP:
    <?php
        
    class templatetweaks_events
        
    {
            function 
    tpl_search_footer()
            {
                echo 
    'Hello World';
            }
        }
    ?>
    #4 in the search.tpl there is this hook call.
    PHP:
    {modulehook function="tpl_search_footer" options=""}
    why is 'Hello World' not displayed at the bottom of the search page?
    I don't get how this hook is called.

    -Tom
  8. Lhotch curmudgeon

    Because you didnt follow the directions when you created your module. As I also stated above you need to "register" your function and tie it to a hook.
  9. tlombard Customer

    my bad...I pasted the first WRONG hook.php content, not what I actually was using.

    here is my hook.php file:

    PHP:
    <?php
        
    class templatetweaks_events
        
    {
            function  
    templatetweaks_events(&$modules)
            {
                
    $modules->register('tpl_search_footer'$this'search_footer');
            }

            function 
    search_footer()
            {
                echo 
    "Hello World";
            }
        }
    ?>
    here is the search page hook call:
    PHP:
    {modulehook function="tpl_search_footer" options=""}
    now what am I missing?

    Lhotch, you always this charming?
  10. tlombard Customer

    Gotta 'Activate' the module...Administration / Settings / Modules
  11. Lhotch curmudgeon

    Only when people keep asking the same question that I already answered.

Share This Page