Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
How can you declare a new asset in Vanilla?
whu606
MVP
Best Answer
-
Todd Vanilla Staff
Okay, so I assume you know how to render assets?
Using smarty:
{asset name="MyAsset"}
Using php:
$this->RenderAsset('MyAsset');
So in your controller method you just need to add a string or
Gdn_Module
asset:$this->AddAsset("MyAsset", "Hello World!");
or
$Module = new Gdn_SomeModule(); $this->AddAsset("MyAsset", $Module);
2
Answers
Okay, so I assume you know how to render assets?
Using smarty:
Using php:
So in your controller method you just need to add a string or
Gdn_Module
asset:or
@Todd
Thanks for getting back so quickly!
thanks @Todd. nice to see these pearls of wisdom every once in a while - it gives us inspiration and helps us understand the inner workings better.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
I wasn't quite sure how to implement Todd's suggestion, but in searching how to, I found this code snippet which did what I was looking for
which I added in to my plugin.php file.
For future reference, Todd's solution was as simple as adding the line he suggested after
public function Base_Render_Before($Sender) {
My plugin (modeled on the Adding some jQuery to a plugin example in the Wiki)
already had
public function Base_Render_Before($Sender) { $this->AddJsCss($Sender);
so all I needed to do was add the lines there:
public function Base_Render_Before($Sender) { $this->AddJsCss($Sender); $this->AddAsset("MyAsset", "Category"); $this->AddAsset("MyAsset", "Table");
nice followup.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.