# D:\cu\cms\mycms\blog\templatetags\blog_extras.py
from django import template
from django.utils.html import strip_tags

register = template.Library()

@register.filter
def two_lines(value):
    """ตัวอย่าง filter ตัด HTML ออก แล้วคืนค่า 2 บรรทัด"""
    if not value:
        return ''

    text = strip_tags(value)
    lines = [line.strip() for line in text.splitlines() if line.strip()]

    if not lines:
        return ''

    line1 = lines[0]
    if len(lines) > 1:
        line2 = ' '.join(lines[1:])
        return line1 + '\n' + line2
    else:
        return line1
