symfony custom form type with assets - forms

I've created a custom form type in symfony2. This formtype has it's own template and this is working fine.
The form type also needs some javascript on the clientside to work nicely.
I would like to add this javascript to the page using the same template I use to render the widget. It's a bit more of a hassle to do this manually.
I could add the javascript manually on each page, but it would be nice if that just happened automatically.
I can't add the javascript just before or after the element itself, as it has a dependency to jquery which is only loaded at the bottom of the body.
I tried using a block which is defined in the "main template" (it is named block_javascript) to add the custom javascripts to the footer of the page, but it seems the rendering of forms works a little different and the block is not available.
I'm using assetic to prepare and return assets.
Is there a way I can use blocks from the main template being rendered when rendering a form widget?

I don't think yet about all the consequences or if it's doable, but here an idea that can solve your problem: use the event dispatcher.
an event for assets addition
a service that hold a list of assets to use and subscribe to above event
a Twig extension that use above service to make assets accessible in the template
trigger the event in the buildView() function of your form type with right parameters
use the Twig extension in your layout template
It theorically should work.

Related

How to add custom javascript in Laravel-Backpack

Is there any way to add custom javascript?
I want to add custom javascript to some of the pages but it seems i am not able to.
Each default Backpack operation has its own CSS and JS file, in:
public/vendor/backpack/crud/css
public/vendor/backpack/crud/js
If you don't find one there, you can create one, and Backpack will pick it up in that operation's view (e.g. create.css or list.js).
Read more: https://backpackforlaravel.com/docs/3.5/crud-how-to#customize-css-and-js-for-default-crud-operations

Is there a way to know when the DOM of a partial view is ready after it is inserted into the DOM of your web page?

I'm writing an application using Knockout. I have subviews I'm inserting via jQuery's append() function. I'm using the text plugin for RequireJS to dynamically retrieve the HTML, then I'm using append() to attach it to an element in my web page:
$("#parentElement").append(theHTML);
After that, I need to bind "theHTML" to my ViewModel:
ko.applyBindings(myViewModel, $("#subViewElement")[0]);
It seems like the jQuery onDomReady() function is only used in the initial loading of the web page. Is there a way to make sure the DOM in "theHTML" is ready before calling "applyBindings" on it?

Preferred way to add an extensions into Fluid Powered TYPO3 template

im working with Claus' Fluid Powered TYPO3 and I'm quiet happy with it. At the moment I have to implement a template wich should contain another extension (e.g. news) in the sidebar.
What is the preferred way to implement this.
My idea was to add the f:cObject ViewHelper and insert the extension in that way.
Is this the correct approach?
Thx
Markus
This depends on the type of template you are building:
Page templates should have proper content areas into which you can insert content. If the content needs to be shared, you have a few options: a) create the element in a sys folder and reference it from your Flux form settings then use v:content.render to render it by UID. b) Place any number of shared elements in a sys folder and render all by PID. c) Use content sliding in a column in your template which is there in all templates and is designed to contain elements which "slide" to every subpage (and can also be edited on subpages if editor has access).
Content templates can use flux:grid with flux:form.column, or flux:form.content as a shortcut to quickly make a single column, to add a content area, then flux:content.render to render those elements. This allows you to control that gets rendered around the plugin.
Plugin templates can associate a Flux form and use the steps described in point 2.
I think you're looking for 1a) or 1c) in this case.

Dojo parse unparsed widjits

Zend framework adds the dojo.parser.parse(); to your script if you have widgets on the page, but not if you don't - makes sense. But I have a common js file which should set up lightbox images within all pages, and for this i need dojo.parser.parse(); to be included. I can add it to my common js file, but if I do, the parser runs twice and dojo breaks because all widgets in the page are getting added twice.
How can I set my js up to effectively look for unparsed items, or even better, would be to detect if dojo.parser.parse(); has already been run? (Unfortunately Zend doesn't assign the dojo.parser.parse(); to a variable)
Once dojo.parser.parse() has finished the parsing of widgets, all the widgets references can be found at the global object dijit.registry._hash. You can use a simple test to check whether this object is empty to determine whether dojo.parser.parse() has been called.
This approach only works when you only create widgets declaratively.

best approach to render site-wide elements using Zend Framework

I'm using the 'modules' front controller resource for the project setup.
What's the best approach to render site-wide elements, like navigation?
Add the action which renders the element to the end of the action stack each request?
is it OK to render these elements through controller actions?
Create a plugin which renders the element?
Could I use module specific plugins?
are there other possible ways to do this?
I think the action stack should be avoided. See this article for why.
The plugin method could work or you can create ViewHelpers which you call from you layout script. I like the ViewHelpers method because it keeps everything very clear. You know that when you echo out $this->mainNaviation() that there is a ViewHelper called MainNavigation.