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 to replace the output html content?
wzttest1
New
Hi:
I'm developing plugin for vanilla.I want to know how to replace the output html content with my plugin?
For example:
I want to add some js code after the html tag,like this:
...
mytestcall();
...
How to implement it?
Thanks!
0
Answers
There is some error with this topic,but I can not edit the topic,so I have submit my question again in a right format.
My question is:
I'm developing plugin for vanilla.I want to know how to replace the output html content with my plugin? For example: I want to add some js code after the body html tag,like this:
<body><script type="text/javascript">mytestcall();</script>
How to implement it?
Thanks.
You would add that in the theme's default.master if I understand what you want correctly .
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
@wzttest1 You would have to implement an event handler and output the HTML with a simple
echo
. As far as I know, there is no event that triggers immediately after the<body>
tag, therefore you would have to use another one.Example
This method, however, is not very "orthodox". Unless you really need to output your script in a specific place, scripts are usually loaded with
$Sender->AddJs()
, which is often called in aBase_Render_Before
handler.My shop | About Me
Hi:
Thank you for your reply.
I need dynamically get and replace some html code of the output html content in my vanilla plugin,not your said theme I think.
Hello:
Thank you for your help.
I assuredly need insert some js code after the body html tag.
As your said,we unable to implement it?
Any help will be appreciative.
btw:
I need implement it in a DiscussionController_BeforeDiscussionRender_Handler method or a before render method.
what's the use of your said BeforeRenderAsset and what's the meaning of your said is not very "orthodox"?
thanks.
BeforeRenderAsset
, as the name implies, is fired before an Asset is rendered. You can search Vanilla code to see where it's fired, or use the Eventi plugin which will show you where the events are fired.By "not orthodox" I meant that, when possible, it's usually preferable not to output HTML piecemeal from a Controller. The reason is to avoid messing things up (if a Controller throws out HTML here and there, it becomes difficult to debug). Besides, if one wants to be "anally retentive" about software design, output belongs in the View layer of the MVC.
This said, I also had to output HTML from the Controller from time to time, and it works fine.
My shop | About Me
You mean the plugin function
function DiscussionController_BeforeRenderAsset_Handler(&$Sender)
should works well for my plugin?Thanks.
I can't really say, I don't know your plugin. Try and see if it does what you expect.
My shop | About Me
Hi:
Sorry.I have tried this code on my plugin,it run the js code many times on one page,and do not run the js after the body tag as I want.
I think this code is not what I need.
Is there other way to implement this requirement?
Vanilla offical team could take a look for this?
Any help would be appreciative.
Thank you!
I know it may not be what you need. As I wrote, there is no event that fires immediately after the
<body>
tag. You might try with theAfterBody
event, but I still think that you should use the Eventi plugin to find the most appropriate event.My shop | About Me
I need my js code just running after the
<body ...>
tag instead of before the</body>
tag.For example:
<body><script type="text/javascript">mytestcall();</script>
As your said means there is not other way to implement the requirement?
Maybe need the vanilla offical guys to help me for this?
Thank you for your help.
Anybody can help for this?
You should not be putting script in the body anyway, it is bad practice.
There is an advanced topic that involves deferring all the JavaScript at the end of the body, this if for those that know what they are doing, as it can easily break something, and it is not for individual plug-ins or scripts.
Even widgets,gadgets, and snippet, can be rewritten so you don't have to directly inject code in the body.
The only reason why this form persists is lot of advertisers, etc don't want to get their customers to do it properly. or developers do it as a temporary measure and never get round to removing it.
grep is your friend.
Hi x00:
Are you vanilla offical guys?
In my project,assuredly need some js code be added after the body tag,so is there any solution for this?
Thank you.
This forum is a community of volunteers. Perhaps we could help you find a better 'how' if you explain 'what' you are trying to accomplish.
Welcome to the community!
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Hi:
It's my work need to do.We need accomplish a feature that generate and insert some block html/js codes after the body tag,for example generate a banner on the top of the site.
Any help would be appreciative.
Thanks.
@wzttest1 you are able to insert html elements into the DOM at any place using jQuery.
Something like this will point you in the right direction:
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Hi:
Thank you for your help.
But I need accomplish a feature that run a js function after the body tag.How to do it?