Hello world tutorial - Why the template variable ?

Hello,

I just finished the first “Hello world” app tutorial. Everything went fine and the app is working, I just don’t understand something which is probably a small mistake in the tutorial : at step 5.2.2, we create a myMessage variable that we send to the template.

Then in the template, at step 5.2.3, we don’t use this variable and instead retrieve the message from $_GET directly. I tried removing the variable in the controller and, as I expected, it didn’t change the app’s behavior.

I guess the goal here was to show how to create a variable in the controller and retrieve it in the template. I’m sure this is also shown in later tutorials, but isn’t a bit weird to introduce something in this tutorial that we don’t actually used ? :slightly_smiling_face:

This might be a residue from former coding techniques.

In the past, we generated the HTML on the server and transmitted everything (multi page application per app). In the meantime, NC suggests to use a Vue frontend (single page application per app mostly). Then, the template no longer needs any dynamic data.

This is just a guess. I have to check manually. I try to have a look next week (I am abroad at the moment).

Chris

I gave your example a spin and by chance found a bug in the tutorials. I already contacted the staff at NC about it.

I would say that you should (in the context of Nextcloud) never use $_GET, $_POST, or similar in your code unless you have a really, really good reason to do it. So, the tutorials also goes against best practices in using $_GET here.

I will ping you once I know the next steps of the tutorial. (CC @Daphne)

Chris

For the sake of completeness: We are talking about this tutorial.

Indeed, the myMessage parameter should be retrievable in the template as $_['myMessage'] instead of $_GET['getParameter']. I’ve fixed this in the tutorial now.

Let us know if you have any other questions.

If possible, delay it a minor bit, @halibut before going through the tutorial. I think there is another issue and I want to avoid you learning wrong stuff. So, please be patient (or be prepared to reread it :wink:)

@christianlupus Sure, thanks for fixing it. :wink: