Welcome to Geeklog, Anonymous Monday, December 23 2024 @ 02:28 am EST

Geeklog Forums

How to add another ?


Turner

Anonymous
In admin/story.php $groupdd accumulates a bunch of html

Text Formatted Code
$groupdd = '';
    if ($access == 3) {
        $groupdd .= '<select name="group_id">';
        for ($i = 0; $i < count($usergroups); $i++) {
            $groupdd .= '<option value="' . $usergroups[key($usergroups)] . '"';
            if ($A['group_id'] == $usergroups[key($usergroups)]) {
                $groupdd .= ' selected="selected"';
            }
            $groupdd .= '>' . key($usergroups) . '</option>';
            next($usergroups);
        }
        $groupdd .= '</select>';
    } else {
        // they can't set the group then
        $groupdd .= DB_getItem ($_TABLES['groups'], 'grp_name',
                                "grp_id = {$A['group_id']}");
        $groupdd .= '<input type="hidden" name="group_id" value="'
                 . $A['group_id'] . '">';
    }
 

Then this accumulated stuff is put in a variable called "group_dropdown".
Text Formatted Code
    $story_templates->set_var('group_dropdown', $groupdd);
 


The variable appears as {group_dropdown} in the storyeditor_advanced.thtml template file.

In a plugin I am trying to write, I collect html in a variable called $STUFF. I have added the variable to the story_advanced template as {STUFF}. How do I get the contents of $STUFF into {STUFF}. I can't just say
Text Formatted Code
$story_templates->set_var('STUFF', $STUFF);
 


What preliminary code must I put in my plugin file to allow me to add this field to the template while leaving everything else alone?
 Quote

ted

Anonymous
it must be set in story.php. your plugin has no hooks there, afics
 Quote

Turner

Anonymous
I was afraid this was the case.

I have a need to also add three fields into the header template. I know I can do this by setting up PHP function calls. But I need to have three different fields added in two different places (head and body) within header.thml. Do I have to make two php calls just to add these three fields. (would be nice to just do it only once).
 Quote

Turner

Anonymous
I'm sorry. I don't mean FIELDS. I mean VARIABLES (with html content)!
 Quote

ted

Anonymous
in your header.thtml
Text Formatted Code
<?php print yourfunction('var1'); ?>
<some html>
<?php print yourfunction('var2'); ?>
etc.
 

and the function placed in lib-custom.php or your theme's functions.inc file.
Text Formatted Code

function yourfunction($var)
{
    if ($var == 'var1'){
        return 'this html';
    } elseif ($var == 'var2'){
        return 'this html';
    }
}
 
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
PLG_templateSetVars would come to mind. I.e. in your plugin, implement a function plugin_templatesetvars_pluginname. It's getting the header template as a parameter, so you can replace any of your own variables (anywhere in header.thtml) in there.

bye, Dirk
 Quote

Turner

Anonymous
Thanks Ted. I'll take a look at your solution if I can't understand Dirk's.

Dirk, I took a look at the PLG_templateSetVars function and think it is exactly what I want. But I am having a hard time understanding it completely.

In my plugin's function.inc there will be a function named plugin_templatesetvars_myplugin'sname. I assume it is here that I put the php that sets up my three variables $stuff1,$stuff2 and $stuff3. The part I am missing is how to get $stuff1 into {stuff1} so I can put {stuff1} in my header.

Do I do this:

Text Formatted Code
function plugin_templatesetvars_<i>myplugin'sname</i> ()
{
    global $_CONF, etc., etc.,;

    (php code that puts content into $stuff1, $stuff2 and $stuff3;)

    PLG_templateSetVars( 'header', $stuff1 );
    PLG_templateSetVars( 'header', $stuff2 );
    PLG_templateSetVars( 'header', $stuff3 );
}
 

Two other questions

A. I guess Geeklog automatically checks its plugins to see if the plugin_templatesetvar_myplugin function is present, and if so, then it just runs the function and sets the variables for the template. I don't have to specifically call the function. Correct?

B. In the same way as setting a var in the header, can I also set a variable in footer.thtml?

Thanks for your help!
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Text Formatted Code
function plugin_templatesetvars_myplugin ($templatename, $template)
{
    if ($templatename == 'header') {
        $template->set_var ('stuff', "Some stuff when in header");
    } else {
        $template->set_var ('stuff', "Some other stuff when elsewhere");
    }
}
 

Something like that. That would set the variable {stuff} to "Some stuff in header" when called for the site's header.

And, yes, that function is called automatically, assuming your plugin is named "myplugin" (which you should obviously replace with the real name of your plugin).

bye, Dirk
 Quote

Turner

Anonymous
I just want to say thanks for this. It works like a charm.
-Jeff
 Quote

All times are EST. The time is now 02:28 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content