I am a Joomla developer who has been asked to start developing Craft plugins and I'm afraid my brain is so moulded to the joomla way of doing things that I cannot even see how the template links to the plugin and fires events
I'm especially interested in form processing (being the cornerstone of application functionality) and I've been taking a look at the contact form plugin. In the contact.html
template I can see {{ getCsrfInput() }}
which is Twig syntax for calling a method- but there is no method called getCsrfInput()
anywhere in the plugin. However it works, hidden fields are returned with an 'action' pointing to contactForm/sendMessage which (I'm assuming the Craft app decides, because there is no form tag action) fires the actionSendMessage event in the contact form plugin.
I just don't see the sequence! I can program PHP fine, but (perhaps due to ONLY doing things the Joomla way) don't see how plugins are called/included in a page.
It's a silly example, but could someone explain to me how I could get a function to just echo Hello World on a page:
function printHello()
{
echo 'Hello world!'
}
Would this go in the plugin root class? If so, what do I put in the example.html
template to call this plugin function?
If I can do that then I can (presumably) use it to do everything else. Just 'including' a PHP function on a page doesn't seem like the Craft way of doing thing- I've read about hooks and events, and they don't make sense to me. Hooks seem to link a plugin to a URI, and it seems to suggest that you don't need to put anything into the template html calling the plugin. The Other, 'Events', is all PHP, so I'm assuming isn't intended to be put into the template files (Any php I put in there is escaped).
So, in short, how can add a hello world output to a page using a plugin (Stupid, but just to get me started)
My thought is that as soon as I can do that I can have a function that grabs form data from a previous page and processes it in order to do some real work.
Thank you so much for your help!
Andy