Block Add and block ID - chicken and egg problem?
PermalinkIt all works fine when in Edit, but when adding a new block every method I have tried for creating the link to the ajax actions fails. My current hypothesis is that all these methods at some point use the block ID, and that during the Add process the block ID does not yet exist (during Edit it does exist, so any of the various methods of creating the action link work fine). Can anyone confirm my assumption about the block ID?
I had a look at other blocks that use a pop up and ajax from the Add/Edit dialog (like autonav and several of the image galleries). Those I have examined use external tools rather than using an action within the controller.
Am I missing something obvious? Has anyone else solved this (other than by making the action an external tool)?
-Steve
also you can move that code to a tools file and use this in it, Loader::block('autonav'); replacing the handle, and that will load the blocks controller,
I would just make the tools file and use it as a thin wrapper for the controller (assuming this is even possible at all -- which it might not be because a bID doesn't exist until the block has been added). Mnkras's code should do the trick. If not, seeing the code would be helpful (and also if you could explain what it is you're trying to do that would help as well -- perhaps we could come up with alternative solutions to the problem).
However, while putting the package together I have come to accept that using an external tools file, as you all suggest, may be the only way I can have ajax within an add dialog.
Thank you all for your advice.
On a related note, having put this example package together, should I submit it to the marketplace (free of course) as it may be of use to others making their first forays into ajax for C5? What changes would you suggest in the package to make it suitable as such a learning tool?
If you really wanted to put something in the marketplace though I would suggest that an example of a block or package that actually does something would be more helpful -- because using ajax in a block add/edit dialog is not a "normal" thing to do, I think that people would need to see an example of how it's actually used in context in order to make sense of it.
-Jordan
I thought about changing it to a how-to, but that would have lost the interactive element and mostly been a synopsis of other documentation. I wanted the interactive side of it to work as a lesson, hence the add-on.
-Steve