J4.x:Şablon Geçersiz Kılmalar
From Joomla! Documentation
Giriş
Joomla elentileri, çıktı görünümlerini HTML ve PHP tarafından oluşturulan HTML işaretlemesini içeren şablon dosyaları ve düzeni, renk şemasını, yazı tiplerini vb. tanımlayan CSS dosyalarıyla tanımlar. Bu özellikle kendi CSS stillerinizle görünümü değiştirebileceğiniz için ihtiyaçlarınıza mükemmel şekilde uygun olabilir. Bazen ek bilgi veya belki daha az bilgi göstermek istersiniz. Bunun için bir şablon geçersiz kılma oluşturmanız gerekir.
Joomla eklentilerinin çoğu, okunması zor olan oldukça karmaşık çıktı şablonlarına sahiptir. Bazılarının üstesinden gelmek için iyi bir HTML, PHP ve CSS anlayışına ihtiyacınız var. Bu makale, aslında oturum açma modülü mod_login'de bulunan oturum kapatma formu için bir geçersiz kılma oluşturarak süreci gösterir. Site sahibi, oturum kapatma formunun, belirli bir süre kullanılmadığında otomatik oturum kapatmanın ne zaman gerçekleşeceğini göstermesini ister.
Örnek: mod_login için Şablon Geçersiz Kılma
Yönetici menüsünde Sistem → Şablonlar → Site Şablonları öğesini seçerek başlayın ve ardından Cassiopeia Ayrıntıları ve Dosyaları öğesini seçin. Bu Şablonlar: Özelleştir (Cassiopeia) formunu açacaktır:
Önemli: Cassiopeia şablonunun bir parçası olarak sağlanan dosyaların hiçbirini düzenlemeyin. Bir sonraki Joomla güncellemesinde bu dosyaların üzerine yazılabilir ve düzenlemeleriniz kaybolacaktır.
Html klasörü, geçersiz kılmaların bulunduğu yerdir. Html klasörünü genişletirseniz, düzenler, mod_custom, mod_menu ve tinymce için zaten geçersiz kılmalar olduğunu göreceksiniz. Her birini genişleterek içlerinde ne olduğunu görün. Bu aşamada mod_login bulunmamaktadır.
Geçersiz Kılmalar Oluştur
Geçersiz kılmalar oluşturabileceğiniz Modüller, Bileşenler, Eklentiler ve Düzenlerin listesini görmek için Geçersiz Kılma Oluştur sekmesini seçin:
Select the mod_login item. The mod_login template php files will be copied into the html folder and you will be returned to the Editor tab. Expand the html and mod_login folders. You will see default.php and default_logout.php.
You do not want the default.php file as that is an override for the login form. Select it and then the Delete File button in the Toolbar. In the alert dialog, Confirm that you wish to delete the file.
Note how easy it is to delete files if you change your mind. And with the Manage Folders button you can delete entire folders too. Be careful not to delete something you did not create yourself.
Edit default_logout.php
In the Editor tab, select the default_logout.php file. Notice the buttons at the top right: Show Original File and Show Differences. The latter has been set to Yes for the following screenshot to show some lines of code added near the top of the file. These lines of code calculate when the user session will expire after loading the page containing the logout form.
The Diff area shows added lines with a green background and deleted lines with a red background. There are no deleted lines in this case. The code is shown here should you wish to copy it to try this yourself.
use Joomla\CMS\Factory;
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
date_default_timezone_set('Europe/London');
$config = Factory::getContainer()->get('config');
$lifetime = $config->get('lifetime', 0);
$time = time() + $lifetime * 60;
$endTime = date('H:i:s', $time); // time() returns a time in seconds already
Further down the override file, line 36, some more lines have been added to output the desired message:
<p class="text-center">
Your session will expire at <br><?php echo $endTime; ?>
</p>
Save and reload the site page containing the logout form.
You should see the logout form change each time the page is reloaded. But what if you should change your mind? Or have different options for different User groups? Welcome to Layouts, the subject of a separate article.
Other Overrides
The Create Overrides tab of the Templates: Customise (Cassiopeia) form is used to create any of the elements of Joomla output for which it is possible to create overrides. The override folder names mostly start with com_, mod_ or plg_. Note that the second part of a plugin override folder signifies the plugin group. Here is an example selection of override folders:
Layout Overrides
Small layout files are often used for individual elements of Joomla! pages. The articles Read More button, the Intro image and the Full image are all examples of elements that are generated by their own layout files. These micro-layouts are found in the /layouts folder. For example, in the Category Blog view, the blog_item.php file contains the code to place the article title, an intro image, the intro text, as well as various other relevant parts of the page. It does so by using a LayoutHelper call passing the layout to use as a parameter. This is an example, the call to insert the Article Title in the blog layout:
<?php echo LayoutHelper::render('joomla.content.blog_style_default_item_title', $this->item); ?>
The location of the file for this particular element is found by replacing the dot symbols with slash symbols, prepending /layouts/ and appending .php:
JOOMLAROOT/layouts/joomla/content/blog_style_default_item_title.php
When an override file is created it is found in:
JOOMLAROOT/templates/cassiopeia/html/layouts/joomla/content/blog_style_default_item_title.php
Further Information
- Template Basics
- Cassiopeia Template Folders and Files
- Cassiopeia Template Customisation
- Template Overrides
- Template Layouts
- Cassiopeia Template Simplified - A Case Study - a simple template based on Cassiopeia