XenForo XenForo'da Değişkenler Şablonda Nasıl Kullanılır?

ArseniC

Premium
Son görülme
Forum listesi görüntüleniyor
Katılım
7 Mar 2025
Konular
84
Mesajlar
184
Tepki puanı
71
Yaş
42
Konum
erzurum
Web sitesi
www.sevgiforum.com.tr
Xenforo da değişkenleri global ve diğer türde değişkenler olarak ayırabiliriz.
XenForo Global (her yerde kullanılabilir) değişkenler:
$visitor: vBulletindeki $bbuserinfo değişkenine benzer.Forumda giriş yapan kullanıcıya ait bilgileri taşır.Bu diziye ait bazı kullanabileceğiniz değişkenler şunlardır:

PHP:
{$visitor.user_id}
{$visitor.username}
{$visitor.user_group_id}

$xenOptions: Bu da vbulletindeki $vboptions değişkenine benzer.Adındanda anlaşılabileceği gibi forum üzerindeki seçenekleri kullanabilmenizi sağlar.Bunu yaparken xf_options tablosunu kullanır.option_id sutünundaki tüm indexler burada kullanılabilir.
Şablon içerisinde kullanmak için örneğin şu referanslara başvurabilirsiniz:

PHP:
{$xenOptions.attachmentExtensions}
{$xenOptions.boardActive}
{$xenOptions.contactEmailAddress}

Peki Diğer değişkenleri nasıl kullanırız?
Xenforodaki kullanılabilir değişkenler her şablondaki kod içinde açıkça tanımlanmıştır.Görüntüleyebildiğiniz tüm şablonlar library/XenForo/ControllerPublic klasörü içinden çağrılır.
Örneğin görüntülediğiniz konular,thread_view şablonunu kullanır.Bu şablona değişken gönderen dosya ise: library/XenForo/ControllerPublic/Thread.php

PHP:
$viewParams = array(
            'thread' => $thread,
            'forum' => $forum,
            'nodeBreadCrumbs' => $ftpHelper->getNodeBreadCrumbs($forum),

            'canReply' => $threadModel->canReplyToThread($thread, $forum),
            'canQuickReply' => $threadModel->canQuickReply($thread, $forum),
            'canEditThread' => $threadModel->canEditThread($thread, $forum),
            'canDeleteThread' => $threadModel->canDeleteThread($thread, $forum, 'soft'),
            'canMoveThread' => $threadModel->canMoveThread($thread, $forum),
            'canWatchThread' => $threadModel->canWatchThread($thread, $forum),

            'deletedPosts' => $deletedPosts,
            'moderatedPots' => $moderatedPosts,

            'inlineModOptions' => $inlineModOptions,

            'posts' => $posts,
            'page' => $page,
            'postsPerPage' => $postsPerPage,
            'totalPosts' => $thread['reply_count'] + 1,
            'postsRemaining' => max(0, $thread['reply_count'] + 1 - ($page * $postsPerPage)),

            'firstPost' => reset($posts),
            'lastPost' => end($posts),
            'unreadLink' => $unreadLink,

            'poll' => $poll,

            'attachmentParams' => $attachmentParams,
            'attachmentConstraints' => $this->getModelFromCache('XenForo_Model_Attachment')->getAttachmentConstraints(),
            'canViewAttachments' => $threadModel->canViewAttachmentsInThread($thread, $forum)
        );

        return $this->responseView('XenForo_ViewPublic_Thread_View', 'thread_view', $viewParams);
    }

Gördüğünüz gibi şablonu çağırmadan önce kullanılacak tüm değişkenleri yukarısında tanımlıyoruz.
$thread ve $forum için şablon içinde kullanabileceğiniz bazı özellikler şöyledir:

PHP:
{$thread.thread_id}
{$thread.title}
{$thread.view_count}
{$forum.node_id}
{$forum.title}
{$forum.message_count}

Tahmin edeeğiniz gibi bu veriler,xf_thread ve xf_forum tablolarından çekilecektir.
$viewParams Değişkenlerini Nasıl Görüntüleyeceğiz?
dump şablon yardımcı değişkeni size herhangi bir $viewParams dizisinin parametrelerinin hangi değişkenlere sahip olduğunu gösterecektir.
Örneğin biz $thread dizisinin tüm alabileceği değişkenleri görelim.
Bunun için thread_view şablonuna bu kodu ekleyelim:

PHP:
{xen:helper dump, $thread}

Kaydedip,herhangi bir konuya girdiğinizde

PHP:
array(30) {
  ["thread_id"] => int(10906)
  ["node_id"] => int(2)
  ["title"] => string(11) "asdfasdfads"
  ["reply_count"] => int(0)
  ["view_count"] => int(32)
  ["user_id"] => int(1)
  ["username"] => string(5) "admin"
  ["post_date"] => int(1286739559)
  ["sticky"] => int(0)
  ["discussion_state"] => string(7) "visible"
  ["discussion_open"] => int(1)
  ["discussion_type"] => string(0) ""
  ["first_post_id"] => int(133983)
  ["first_post_likes"] => int(0)
  ["last_post_date"] => int(1286739559)
  ["last_post_id"] => int(133983)
  ["last_post_user_id"] => int(1)
  ["last_post_username"] => string(5) "admin"
  ["thread_read_date"] => int(1286739559)
  ["thread_is_watched"] => int(0)
  ["lastPostInfo"] => array(4) {
    ["post_date"] => int(1286739559)
    ["post_id"] => int(133983)
    ["user_id"] => int(1)
    ["username"] => string(5) "admin"
  }
  ["canInlineMod"] => bool(true)
  ["canEditThread"] => bool(true)
  ["isNew"] => bool(false)
  ["hasPreview"] => bool(true)
  ["isRedirect"] => bool(false)
  ["isDeleted"] => bool(false)
  ["isModerated"] => bool(false)
  ["titleCensored"] => bool(true)
  ["lastPageNumbers"] => bool(false)
}

Bu tarz bi çıktı göreceksiniz.
Diğer bir örnekte $visitor dizisini inceleyelim.Bİliyorsunuz bu değişken her yerde çalışabliyordu.

PHP:
{xen:helper dump, $visitor}

Kaydedip sayfayı yenilediğinizde;
$visitor dizisine ait tüm değişkenleri görebilirsiniz.


 
Geri
Üst Alt