-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logic on head.html #345
Comments
Hi Luca :) BUT this can't be done from theme's function.js because head.html template (and layout.html) are loaded early in the process and can't be handled from theme (for now). Only WP-AppKit addons can hook early enough to modify things in head or layout templates. So what you want to do could be done from an addon. A WP-AppKit addon is just a WordPress plugin that hooks into specific WP-AppKit hooks. |
Hi, I've seen the documentation for the addon, but it does not say too much to me... I've tried to make one for other purposes, but going nowhere :D |
Ok great :D Here's an addon bootstrap that you can use: https://github.com/mleroi/wpak-addon-test. To make the PersistentStorage module available in head.html you can modify this wpak-addon-test.js file like so:
To install the addon: install it like a regular WordPress plugin, then you'll see it appear in your app edition panel under Addons > WP-AppKit Addon Test > check the checkbox to activate the addon for your app. Hope that helps, |
Hi Mathieu,
sorry for the late reply but have found time to try this just now. I made
the plugn in wordpress and it appears in the app panel.
The method seems to work in the app preview, but it seems not to work in
the real app on the phone. Need to do some investigation on why this
happening and if really it does not work or there is something else in the
process that's not woring.
All I do in the head file is, if a certain prop saved in the permanent
storage exists and is true, then I write a link to reference a certain css
file, otherwise not.
Thanks,
Luca
2017-11-16 22:28 GMT+01:00 Mathieu Le Roi <notifications@github.com>:
… Ok great :D
Here's an addon bootstrap that you can use: https://github.com/mleroi/
wpak-addon-test.
Used as is, it will just include the wpak-addon-test.js
<https://github.com/mleroi/wpak-addon-test/blob/master/js/wpak-addon-test.js>
JS file at the beginning of the app initialization process.
To make the *PersistentStorage* module available in *head.html* you can
modify this *wpak-addon-test.js* file like so:
define( [ 'core/theme-app', 'core/modules/persistent-storage' ], function ( App, PersistentStorage ) {
App.filter( 'template-args', function ( template_args, view_type ) {
if ( view_type === 'head' ) {
template_args.PersistentStorage = PersistentStorage;
}
return template_args;
} );
} );
To install the addon: install it like a regular WordPress plugin, then
you'll see it appear in your app edition panel under *Addons* > *WP-AppKit
Addon Test* > check the checkbox to activate the addon for your app.
Hope that helps,
Don't hesitate for any question.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#345 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMjXvNBjIK3InMJD2roM43WNi0BFJoAMks5s3KkZgaJpZM4QffH6>
.
|
Hi Matieu, These are the php plugin and js file I had (the js file is on the folder js of the php wordpress plugin folder, but tried to put it also on the js folder of the app:
JS File:
Code in the heasd.html:
Am I missing something? Thanks! |
Hi Luca, |
Damn!!! I've found the problem!!! |
Hi Luca, no problem, we know the export/build/config process can be tricky ;) |
Hi,
I would like to ask a question. I wondering if there is any way to put some logic in the head.html file. What I would like to do is to read the persistent storage to check fore some setting and i.e. load some css files or some other based on the setting value. But trying it it says, probably correctly, that the PersistentStorage object is not available! Any way? Or the only way is to put the logic on the function.js and hence loading the file via js?
Thanks :)
The text was updated successfully, but these errors were encountered: