Make a Lasting Impression





accessing system data in preloads
Home away from home
Joined:
2009/3/3 4:18
From Belgium
Posts: 1952
Hi, I'm working on a preload to dynamically add Social Media metatags to the pages you're viewing. Adding basic stuff that is the same for each page is working ok,and getting the preload to fire is ok too. WHat I can't seem to figure out is hwo to get access to the data of the current page, such as page title and the likes.

This is the code I have working in the plugins/preloads/socialmeta.php file:


class IcmsPreloadSocialmeta extends icms_preload_Item {
    
/**
     * Function to be triggered at the end of the core boot process
     *
     * @return    void
     */

    
function eventBeforeFooter() {
        global 
$xoopsTpl;
        global 
$icmsTheme;

        
$icmsTheme->addMeta('meta','twitter:splut','blabla');


    }
}


Some questions : is the eventBeforeFooter the correct one? I was using eventStartOutputInit but was not sure if the data I am after is already in the system.

Any idea on how I can get access to the theme variables? I have access to icmsTheme, but how do I get to the variables that are passed through there, such as icms_pagetitle in the template?

I was thinking of doing something like this :


$icmsTheme
->addMeta('meta','icms:metatest'$icmsTheme->templateVars['icms_pagetitle']
            );


But that is always empty. Would you have any ideas?

Posted on: 2016/3/27 23:45
_________________
d-log - My personal site
Openhub profile
Transfer the post to other applications Transfer


Re: accessing system data in preloads
Home away from home
Joined:
2007/12/4 9:00
Posts: 4242
There is a plugin to help with preloads! I wrote this a while back to help me figure out some of the same things.

I like the idea - in the past, I wrote these into the theme. This would make them available, no matter what theme you used.

As for when the information is available, rendering takes places in the footer (/footer.php), so all variables are set by then. In the header (startOutputInit), very few, if any, are set.

Posted on: 2016/3/29 1:55
_________________
Steve
Twitter: @skenow
Facebook: Steve Kenow
Transfer the post to other applications Transfer


Re: accessing system data in preloads
Home away from home
Joined:
2009/3/3 4:18
From Belgium
Posts: 1952
Super, thanks for that, that plugin really comes in handy!

I'm thinking of extracting the Google analytics code from where it's now and put it into a preload as well. That would make it easier to replace with some other analytics option, as well as add special taggings to the page (such as special javascript to track downloads or other events) during rendering of the page. On my to-do-soon list, now that I'm having some knowledge of preloads

Posted on: 2016/3/29 8:04
_________________
d-log - My personal site
Openhub profile
Transfer the post to other applications Transfer


Re: accessing system data in preloads
Home away from home
Joined:
2009/3/3 4:18
From Belgium
Posts: 1952
I found how I can access the theme template variables in my preload:

$icmsTheme
->addMeta('meta','icms:flops'$xoopsTpl->_tpl_vars["icms_pagetitle"]);


This adds metadata type 'icms:flops' with the value of the icms_pagetitle template variable.

I'm still puzzled why this works with the xoopsTpl variable, and not with the $icmsTheme->templateVars code.

Posted on: 2016/3/29 13:55
_________________
d-log - My personal site
Openhub profile
Transfer the post to other applications Transfer


Re: accessing system data in preloads
Home away from home
Joined:
2009/3/3 4:18
From Belgium
Posts: 1952
Just a note : at the moment there seem to be issues with preloads on the 2.0 alpha branch. I can't get my preloads to work, while exactly the same files work on the 1.3 branch (tested on 1.3.9 and 1.3.10 alpha)

Posted on: 2016/8/10 13:18
_________________
d-log - My personal site
Openhub profile
Transfer the post to other applications Transfer






You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.

[Advanced Search]