Bản mẫu:Ifnotempty

Bách khoa toàn thư mở Wikipedia


Tài liệu bản mẫu

With this template #if can be used in a way such that it does not strip spaces and newlines from the "then" and "else" part. For evaluating the condition spaces and newlines are stripped like with ParserFunctions.

Bản mẫu này có thể được thay thế.

Cách sử dụng

  • {{ifnotempty| x | A | B }} cho ra " A "
  • {{ifnotempty|x| A | B }} cho ra " A "
  • {{ifnotempty| | A | B }} cho ra " B "
  • {{ifnotempty|| A | B }} cho ra " B "

So sánh:

  • {{#if:x| A | B }} cho ra "A"
  • {{#if:| A | B }} cho ra "B"

Chi tiết kỹ thuật nội bộ

For evaluating the condition (determining non-emptiness of the first parameter) the template uses parser function #if, producing 1 if the condition is true, and 2 otherwise. The template with name equal to "P" followed by the index value produced (hence Bản mẫu:P1 or Bản mẫu:P2), is called with as parameters A and B. This produces either A or B, without trimming.

Xem thêm