Help needed with sending data to an asset
I'm writing my first plugin, and getting there slowly!
The plugin requires modding the custom theme default.master.php file.
I have now been shown how to create an asset, and would like to be able to define the changes to the default.master in my plugin.php file, and send it to an asset, so that in the default.master file the user only has to add the line
<?php $this->RenderAsset('ASSETNAME'); ?>
I've been looking at other plugins, and I've tried using
public function ToString() {
like this
public function AssetTarget() { return 'ASSETTNAME'; } public function ToString() { $String = ''; ob_start(); ?> Testing <?php $String = ob_get_contents(); @ob_end_clean(); return $String; } </pre> NOTE in line 13 the <a href is NOT part of the original code. Either I've got some of that wrong, or I'm trying completely the wrong thing, as that doesn't send the data to my page. As you can probably tell, I don't really know how the coding works, I'm just trying to copy what I see has worked for others. If anyone has a healthy nudge they could give me as to what I should do, I would be very grateful.
Best Answer
-
Todd Vanilla Staff
Can I make another suggestion? Make a module. They are made to put in the site. You can put the module file in your plugin as a separate file or declare it in your default plugin file.
Here is a quick module:
class HelloWorldModule extends Gdn_Module { public function __construct() { $this->Path(__FILE__); // important for forwards-compat } pubic function ToString() { echo "Hello World!"; } }
Simple.
To render a module in the master view you can do the following:
{module name="HelloWorldModule"}
In PHP:
echo Gdn_Theme::Module("HelloWorldModule");
We have future plans for plugin developers to just have to make modules and they'll be available as widgets in the application. We aren't quite there yet so you'll have to call the module tag/function.
To answer your first question you need to do the following in your plugin:
public function Base_Render_Before($Sender) { $Sender->AddModule('HelloWorldModule', 'ASSETTARGET'); }
You can provide the asset target or leave it out in which case it'll use the asset target you declare in your module. Giving the module name instead of a module instance means that the module will be lazy-loaded which is nice to have.
2
Answers
I don't understand your question, but at the same time it is probably over my head.
Could you explain it a bit more in functional terms, perhaps.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
@peregrine
I'll certainly try!
On my test site I added a a slide out feature to hold the 'Panel' assets, and any other bits and bobs you might want on the right hand side (e.g. Quick Links, photos etc.)
So, in my example I have 4 slide out links.
Each of those links requires some markup to be added to the default.master.php file.
It all works fine for me, but now I'm trying to make what I've done a plugin, so I can share it.
As far as I can see in Vanilla, when you call an asset, e.g. Panel, using
everything that is declared to (related to?) that asset appears on the page where it is called.
I could provide the markup in a text file, and tell anyone who wanted to try it to just paste it into the relevant part of their theme's default.php file, but since I now know how to declare a new asset, e.g. Slider, I thought if I could associate the markup with that asset then all the user would need to add would be
The snag is, that whilst I can create a new asset, I don't know how to associate anything with it!
I hope that is clearer.
Frankly, if it's over your head then it's way beyond mine!
I'm in the area of cargo-cult programming (as noted by x00) - so i could be giving you bogus info.
does this help at all.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Can I make another suggestion? Make a module. They are made to put in the site. You can put the module file in your plugin as a separate file or declare it in your default plugin file.
Here is a quick module:
Simple.
To render a module in the master view you can do the following:
In PHP:
We have future plans for plugin developers to just have to make modules and they'll be available as widgets in the application. We aren't quite there yet so you'll have to call the module tag/function.
To answer your first question you need to do the following in your plugin:
You can provide the asset target or leave it out in which case it'll use the asset target you declare in your module. Giving the module name instead of a module instance means that the module will be lazy-loaded which is nice to have.
Thanks again, Todd.
I do appreciate your patience in helping me in my stumbling atempts to work things out.