Addon 2x Template Parent - Thêm biến templateParent cho XenForo 2 1.0.1

PVS

Super Moderator
Thành viên BQT
Template Parent - Thêm biến templateParent cho XenForo 2 1.0.1

Thêm một biến template mới $xf.reply.templateParent để nhóm tất cả các template thread_view*forum_view* lại với nhau.

XenForo 2.2 thêm nhiều biến thể cho các template thread_viewforum_view cho các loại chủ đề mới khác nhau:
  • thread_view_type_article
  • thread_view_type_poll
  • thread_view_type_question
  • thread_view_type_suggestion
  • forum_view_type_article
  • forum_view_type_question
  • forum_view_type_suggestion
Vì vậy, bây giờ khi bạn muốn nhắm mục tiêu một template có điều kiện đến trang thread view (ví dụ: trong một quảng cáo), thay vì trước đây làm như sau:
HTML:
<xf:if is="$xf.reply.template == 'thread_view'">
    <!-- do something -->
</xf:if>

... bây giờ chúng ta phải làm như sau:
HTML:
<xf:if is="in_array($xf.reply.template, [
                'thread_view',
                'thread_view_type_article',
                'thread_view_type_poll',
                'thread_view_type_question',
                'thread_view_type_suggestion'
               ])">
    <!-- do something -->
</xf:if>

Một cách dễ dàng hơn

Add-on này thêm một biến template mới mà chúng ta có thể sử dụng để kiểm tra xem template "parent" là thread_view hay forum_view, vì vậy chúng ta có thể chỉ cần làm như sau để nhắm mục tiêu tất cả các template thuộc loại đó:
HTML:
<xf:if is="$xf.reply.templateParent == 'thread_view'">
    <!-- do something for any thread view pages -->
</xf:if>

... hoặc:
Mã:
<xf:if is="$xf.reply.templateParent == 'forum_view'">
    <!-- do something for any forum view pages -->
</xf:if>

Lưu ý rằng cần có phiên bản v1.0.1 trở lên để tương thích với XF 2.3.

Chúc các bạn thành công.


Nguồn: xenforo.com​
 

Đính kèm

Back
Top