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_Moduleasset:$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:
{asset name="MyAsset"}Using php:
$this->RenderAsset('MyAsset');So in your controller method you just need to add a string or
Gdn_Moduleasset:$this->AddAsset("MyAsset", "Hello World!");or
$Module = new Gdn_SomeModule(); $this->AddAsset("MyAsset", $Module);@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
public function AddAsset($AssetContainer, $Asset, $AssetName = 'NEWASSETNAME') { if (is_object($AssetName)) { return FALSE; } else if ($AssetName == 'NEWASSETNAME') { $this->Assets[$AssetContainer][] = $Asset; } else { if (isset($this->Assets[$AssetContainer][$AssetName])) $this->Assets[$AssetContainer][$AssetName] .= $Asset; else $this->Assets[$AssetContainer][$AssetName] = $Asset; }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.