Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Before we wrap up this module, I want to implement one more thing
here in the Home template. At the moment we have two posts in the
database, but what if we had none?
Let's test this scenario. Inside of the phpMyAdmin,
I will remove both of the existing posts from the database.
You can also do that in the command line or in whichever way you
prefer, as long as the posts table is empty.
If I refresh the Home page now, you can see that all we get is
a blank page, which is kind of expected,
but again, this is not really good user experience.
We could of course add an if directive first to check if the post
collection is empty before rendering this foreach loop, and there is
nothing wrong with that approach. However,
there is a better built‑in way to do this. Instead of using
foreach, let's use the forelse directive.
The functionality of these two directives is basically the same,
but we get some additional features with forelse.
We can add this empty directive inside of the forelse block
to define what would happen if the variable that we are
trying to loop over is empty.
If that's the case, I will render a simple message.
This empty directive works kind of like an else statement. And if I refresh the
Home page now, you can see that instead of a blank page, we now get this useful
message informing us that everything is fine,
but there are no posts in the database yet.
Maybe this doesn't seem like something important, but I think
that you will often have the need to show something else in case
that there is no data to display.
If you have any questions, don't hesitate to post them in the discussion.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.